8.9k views
2 votes
Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg constructor. Which of the following is correct? (Select all that apply)

A. B b = new B();
B. B b = new A();
C. A a = new A();
D. A a = new B();
E. None of the above

User Max N
by
8.0k points

1 Answer

6 votes

Final answer:

Options A (B b = new B();) and D (A a = new B();) are correct. You cannot instantiate an abstract class, which is why options B and C are incorrect.

Step-by-step explanation:

The question you've asked pertains to abstract classes and inheritance in object-oriented programming, which often comes under the subject area of Computers and Technology, at the College level. Specifically, it deals with the instantiation of classes in Java or a similar language.

Given the options, let's analyze them:

  • A. B b = new B(); This is correct. B is a concrete subclass, which means objects of class B can be instantiated.
  • B. B b = new A(); This statement is incorrect because you cannot instantiate an abstract class directly.
  • C. A a = new A(); This is incorrect as well. A is an abstract class, so it cannot be instantiated.
  • D. A a = new B(); This is correct. An abstract class reference can point to a concrete subclass object.

Therefore, the correct answers to the question are: A and D.

User Ozgrozer
by
8.2k points