Bird
0
0

Which of the following is the correct way to declare an abstract method inside an abstract class?

easy📝 Syntax Q12 of 15
Java - Abstraction

Which of the following is the correct way to declare an abstract method inside an abstract class?

public abstract class Shape {
    ?
}
Apublic void draw();
Bvoid draw() {}
Cabstract void draw();
Dpublic abstract void draw();
Step-by-Step Solution
Solution:
  1. Step 1: Recall abstract method syntax

    Abstract methods must be declared with the 'abstract' keyword and no body, and usually have a visibility modifier.
  2. Step 2: Check each option

    public abstract void draw(); correctly declares 'public abstract void draw();'. public void draw(); misses 'abstract', C misses visibility, D has a method body which is invalid for abstract methods.
  3. Final Answer:

    public abstract void draw(); -> Option D
  4. Quick Check:

    Abstract method = 'public abstract' + no body [OK]
Quick Trick: Abstract methods have no body and use 'abstract' keyword [OK]
Common Mistakes:
  • Omitting the 'abstract' keyword
  • Providing a method body for abstract methods
  • Missing visibility modifier

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes