Java Inheritance Mcqs
Our collections of Multiple choice questions and answers focuses on study of Java Inheritance. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Inheritance topic comprehensively.
Java Programming Mcqs
- Data Types Variables and Arrays Mcqs
- Exception Handling in Java Mcqs
- Interfaces and Packages Mcqs
- Java Classes and Methods Mcqs
- Java Event Handling Mcqs
- Java Inheritance Mcqs
- Java IO and Applets Mcqs
- java lang and java io Mcqs
- Java Language Fundamentals Mcqs
- Java Operators and Control Statements Mcqs
- java utilities Mcqs
- Miscellaneous Topics in Java Mcqs
- Multithreading in Java Mcqs
- Serialization and Networking Mcqs
- Session Management and JSP and Servlet Mcqs
- String Handling
Computer MCQS
Sciences MCQS
17.
Which of the following is used for implementing inheritance through an interface?
Inherited
Using
Extends
Implements
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
18.
Which of the following is used for implementing inheritance through class?
Inherited
Using
Extends
Implements
19.
What would be the result if a class extends two interfaces and both have a method with same name and signature?
Runtime error
Compile time error
Code runs successfully
First called method is executed successfully
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
20.
Which of this keyword can be used in a subclass to call the constructor of superclass?
Super
This
Extent
Extends
21.
What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
Method overloading
Method overriding
Method hiding
None of the mentioned
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
22.
Which of these keywords can be used to prevent Method overriding?
Static
Constant
Protected
Final
23.
Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
Super(void);
Superclass.();
Super.A();
Super();
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
25.
Which of these is supported by method overriding in Java?
Abstraction
Encapsulation
Polymorphism
None of the mentioned
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
26.
What is the output of this program?
class Alligator
{
public static void main(String[] args)
{
int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
int [][]y = x;
System.out.println(y[2][1]);
}
}
class Alligator
{
public static void main(String[] args)
{
int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
int [][]y = x;
System.out.println(y[2][1]);
}
}
2
3
7
Compilation Error
27.
What is the output of this program?
final class A
{
int i;
}
class B extends A
{
int j;
System.out.println(j + " " + i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
final class A
{
int i;
}
class B extends A
{
int j;
System.out.println(j + " " + i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
2 2
3 3
Runtime Error
Compilation Error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
28.
What is the output of this program?
class Abc
{
public static void main(String[]args)
{
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0]: null;
}
}
class Abc
{
public static void main(String[]args)
{
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0]: null;
}
}
Compilation error
An exception is thrown at run time
The variable first is set to null
The variable first is set to elements[0].
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
29.
What is the output of this program?
class A
{
int i;
public void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
public void display()
{
System.out.println(j);
}
}
class Dynamic_dispatch
{
public static void main(String args[])
{
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
r.display();
}
}
class A
{
int i;
public void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
public void display()
{
System.out.println(j);
}
}
class Dynamic_dispatch
{
public static void main(String args[])
{
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
r.display();
}
}
1
2
3
4
30.
What is the output of this program?
class Output
{
public static void main(String args[])
{
Object obj = new Object();
System.out.print(obj.getclass());
}
}
class Output
{
public static void main(String args[])
{
Object obj = new Object();
System.out.print(obj.getclass());
}
}
Object
Class Object
Class java.lang.Object
Compilation Error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question
31.
What is the output of this program?
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}
True
False
String associated with obj1
Compilation Error
Answer & Solution
No Solution for this Answer..! Report or Discus this Question