Multiple choice technology

Which of the following statements about abstract methods/classes in Java are true?1. An abstract class cannot be instantiated.2. Constructors cannot be abstract.3. A subclass of an abstract class must defined the abstract methods.4. Static methods may be declared abstract.

  1. Line 1, line 2 and line 3 only

  2. Line 1 only

  3. Line 1 and line 2 only

  4. Line 2 only

  5. All are true

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Statement 1 is true - abstract classes cannot be instantiated directly. Statement 2 is true - constructors are never abstract; they're concrete by definition. Statement 3 is false - a subclass can remain abstract and not implement all abstract methods. Statement 4 is false - static methods belong to the class, not instances, so they cannot be abstract.

AI explanation

To answer this question, let's go through each statement to understand whether it is true or false:

Statement 1: An abstract class cannot be instantiated. This statement is true. An abstract class cannot be directly instantiated, meaning you cannot create an object of an abstract class. However, you can create subclasses of an abstract class and instantiate those subclasses.

Statement 2: Constructors cannot be abstract. This statement is true. Constructors cannot be declared as abstract because constructors are responsible for initializing objects, and abstract methods have no implementation.

Statement 3: A subclass of an abstract class must define the abstract methods. This statement is true. If a class extends an abstract class, it must provide implementations for all the abstract methods defined in the abstract class. Failure to do so will result in a compilation error.

Statement 4: Static methods may be declared abstract. This statement is false. Static methods cannot be declared as abstract because abstract methods are meant to be overridden in subclasses, but static methods belong to the class itself and cannot be overridden.

Based on the explanations above, the correct answer is C) Line 1 and Line 2 only.