226k views
0 votes
Which of the following are incorrect? Group of answer choices An interface can contain constructors. You may declare a final abstract class. The constructors in an abstract class should be private. An abstract class can contain constructors.

2 Answers

4 votes

Answer:

Incorrect options are;

i. An interface can contain constructors

iii. The constructors in an abstract class should be private.

Step-by-step explanation:

Option i is incorrect. An interface cannot be instantiated (object cannot be created from it) or extended (classes cannot inherit from it) and as such no constructors are needed.

Option ii is correct. You may declare a final abstract class. This would just mean the class cannot be instantiated and neither can it be extended. That would also mean a redundant class.

Option iii is incorrect. A constructor in an abstract class should not be made private (although possible). Otherwise, not only will it not be instantiable, it will also not be extensible.

Option iv is correct. An abstract class can contain constructors. Since abstract classes can be extended, having constructors in them will allow classes, that inherit from them, to be able to create objects from them.

4 votes

Answer:

Step-by-step explanation:

1. The answer is No, interface cannot have constructors. ... In order to call any method we need an object since there is no need to have object of interface, there is no need of having constructor in interface (Constructor is being called during creation of object).

2.A final class is considered complete and can not be subclassed (It's methods can not be overridden ). In case of abstract class, we have to proved implementation to abstract methods in subclasses. A final class can not have abstract methods and an abstract class can not be declared final.

3.private constructors are acceptable, however the class should be marked final instead, as doing so means the class is to be extended.

4.Yes! Abstract classes can have constructors! Yes, when we define a class to be an Abstract Class it cannot be instantiated(i.e an object cannot be created) but that does not mean an Abstract class cannot have a constructor. Each abstract class must have a concrete subclass which will implement the abstract methods of that abstract class.

User Sarah Weinberger
by
5.2k points