Examveda
Examveda

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct?
1. A a = new A();
2. A a = new B();
3. B b = new A();
4. B b = new B();

A. 1 and 2

B. 2 and 4

C. 3 and 4

D. 1 and 3

E. 2 and 3

Answer: Option B


This Question Belongs to Java Program >> Interfaces And Abstract Classes

Join The Discussion

Comments ( 1 )

  1. Akash Mulik
    Akash Mulik :
    7 years ago

    Option 1. & 3. is wrong because we cant create object of abstract class.
    2 & 4 are correct because B is concrete class and its object is created and in Option 2, reference of class A(abstract class) can be used to hold its child class's object.

Related Questions on Interfaces and Abstract Classes

What is an interface in Java?

A. A contract specifying a set of methods that a class must implement

B. A class that cannot be instantiated

C. A class that contains only static methods

D. A subclass of the Object class