Which statement is true about interface and abstract classes?

  1. A class may inherit several interfaces, A class may inherit only one abstract class

  2. An abstract class may only contain incomplete methods (abstract methods)

  3. An interface may contain complete or incomplete methods

  4. A class implementing an abstract class has to implement all the methods of the abstract class, but the same is not required in the case of an interface


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A class may inherit several interfaces, A class may inherit only one abstract class - This option is correct. In Java, a class can implement multiple interfaces, but it can only inherit (extend) one abstract class. This is because Java does not support multiple inheritance of classes.

Option B) An abstract class may only contain incomplete methods (abstract methods) - This option is incorrect. An abstract class can contain both abstract methods and concrete methods (i.e., methods with an implementation). Abstract methods are those that do not have a body and are meant to be overridden by the subclasses.

Option C) An interface may contain complete or incomplete methods - This option is correct. An interface can contain both complete (default) methods and incomplete (abstract) methods. Complete methods have a body and are inherited as they are, while incomplete methods do not have a body and must be implemented by the classes that implement the interface.

Option D) A class implementing an abstract class has to implement all the methods of the abstract class, but the same is not required in the case of an interface - This option is incorrect. In both cases, when a class implements an abstract class or an interface, it must provide an implementation for all the methods declared in the abstract class or interface. Otherwise, the class must be declared as abstract.

The correct answer is A) A class may inherit several interfaces, A class may inherit only one abstract class. This option is correct because it accurately describes the difference between inheriting interfaces and abstract classes in Java.

Find more quizzes: