JOIN US
Object oriented programming Java
Which of this keyword must be used to inherit a class?
a) super
b) this
c) extent
d) extends
Answer: d
A class member declared protected becomes a member of subclass of which
type?
a) public member
b) private member
c) protected member
d) static member
Answer: b
Which of these is correct way of inheriting class A by class B?
a) class B + class A {}
b) class B inherits class A {}
c) class B extends A {}
d) class B extends class A {}
Answer: c
Which two classes use the Shape class correctly?
A. public class Circle implements Shape
{
private int radius;
}
B. public abstract class Circle extends Shape
{
private int radius;
}
C. public class Circle extends Shape
{
private int radius;
public void draw();
}
D. public abstract class Circle implements Shape
{
private int radius;
public void draw();
}
E. public class Circle extends Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
F. public abstract class Circle implements Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
a)B,E
b)A,C
c)C,E
d)T,H
Answer: a
What will be the output of the following Java program?
-
class A
-
{
-
int i;
-
void display()
-
{
-
System.out.println(i);
-
}
-
}
-
class B extends A
-
{
-
int j;
-
void display()
-
{
-
System.out.println(j);
-
}
-
}
-
class inheritance_demo
-
{
-
public static void main(String args[])
-
{
-
B obj = new B();
-
obj.i=1;
-
obj.j=2;
-
obj.display();
-
}
-
}
a) 0
b) 1
c) 2
d) Compilation Error
Answer: c
What is not type of inheritance?
a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance
Answer: b
Using which of the following, multiple inheritance in Java can be
implemented?
a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods
Answer: a
All classes in Java are inherited from which class?
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.Object
Answer: d
In order to restrict a variable of a class from inheriting to
subclass, how variable should be declared?
a) Protected
b) Private
c) Public
d) Static
Answer: b
If super class and subclass have same variable name, which keyword
should be used to use super class?
a) super
b) this
c) upper
d) classname
Answer: a
Static members are not inherited to subclass.
a) True
b) False
Answer: b
Which of the following is used for implementing inheritance through
an interface?
a) inherited
b) using
c) extends
d) implements
Answer: d
Which of the following is used for implementing inheritance through
class?
a) inherited
b) using
c) extends
d) implements
Answer: c
What would be the result if a class extends two interfaces and both have a
method with same name and signature? Lets assume that the class is not
implementing that method.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully
Answer: b
Does Java support multiple level inheritance?
a) True
b) False
Answer: a
Which of these keywords are used to define an abstract class?
a) abst
b) abstract
c) Abstract
d) abstract class
Answer: b
Which of these is not abstract?
a) Thread
b) AbstractList
c) List
d) None of the Mentioned
Answer: a
If a class inheriting an abstract class does not define all of its
function then it will be known as?
a) Abstract
b) A simple class
c) Static class
d) None of the mentioned
Answer: a
Which of these is not a correct statement?
a) Every class containing abstract method must be declared abstract
b) Abstract class defines only the structure of the class not its
implementation
c) Abstract class can be initiated by new operator
d) Abstract class can be inherited
Answer: c
Which of these packages contains abstract keyword?
a) java.lang
b) java.util
c) java.io
d) java.system
Answer: a
What will be the output of the following Java code?
-
class A
-
{
-
public int i;
-
private int j;
-
}
-
class B extends A
-
{
-
void display()
-
{
-
super.j = super.i + 1;
-
System.out.println(super.i + " " + super.j);
-
}
-
}
-
class inheritance
-
{
-
public static void main(String args[])
-
{
-
B obj = new B();
-
obj.i=1;
-
obj.j=2;
-
obj.display();
-
}
-
}
-
2 2
b) 3 3
c) Runtime Error
d) Compilation Error
Answer: d
What will be the output of the following Java code?
-
class A
-
{
-
int i;
-
void display()
-
{
-
System.out.println(i);
-
}
-
}
-
class B extends A
-
{
-
int j;
-
void display()
-
{
-
System.out.println(j);
-
}
-
}
-
class method_overriding
-
{
-
public static void main(String args[])
-
{
-
B obj = new B();
-
obj.i=1;
-
obj.j=2;
-
obj.display();
-
}
-
}
Answer: c
What will be the output of the following Java code?
-
class A
-
{
-
public int i;
-
protected int j;
-
}
-
class B extends A
-
{
-
int j;
-
void display()
-
{
-
super.j = 3;
-
System.out.println(i + " " + j);
-
}
-
}
-
class Output
-
{
-
public static void main(String args[])
-
{
-
B obj = new B();
-
obj.i=1;
-
obj.j=2;
-
obj.display();
-
}
-
}
a)12
b)21
c)13
d) 3 1
Answer: a
POLYMORPHISM
Which of the following is not OOPS concept in Java?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
Answer: d
Which of the following is a type of polymorphism in Java?
a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism
Answer: a
When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time
Answer: b
When Overloading does not occur?
a) More than one method with same name but different method signature and
different number or type of parameters
b) More than one method with same name, same signature but different number
of signature
c) More than one method with same name, same signature, same number of
parameters but different type
d) More than one method with same name, same number of parameters and type
but different signature
Answer: d
Which concept of Java is a way of converting real world objects in terms of
class?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
Answer: c
Which concept of Java is achieved by combining methods and attribute into a
class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
Answer: a
Method overriding is combination of inheritance and polymorphism?
a) True
b) false
Answer: a
0 Comments
Please feel free to comment. Being diploma students We are always ready to help diploma Students