158k views
3 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?

1) a cannot be instantiated
2) cannot be instantiated
3) a can be instantiated but b cannot be instantiated
4) both a and b can be instantiated

User MarJano
by
8.8k points

1 Answer

2 votes

Final answer:

Option 1 is correct because abstract classes cannot be instantiated, but their concrete subclasses can be if they provide full implementations.

Step-by-step explanation:

The correct answer is option 1) a cannot be instantiated. In object-oriented programming, an abstract class is designed to be a base class that cannot be instantiated on its own, meaning you cannot create objects directly from an abstract class. However, a concrete subclass, which in this case is b, can indeed be instantiated because it is a fully implemented class that extends the abstract class a. The presence of no-arg constructors in both the abstract class and the concrete subclass does not change this fundamental rule of abstract classes and instantiation.

An abstract class cannot be directly instantiated, meaning you cannot create an object of the abstract class itself. However, you can create objects of its concrete subclasses, such as b. The no-arg constructor in both the abstract class a and the subclass b allows for the creation of instances of both classes.

User RemoteSojourner
by
8.4k points