Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Java - Abstraction

Identify the error in the following code snippet:

abstract class Shape {
    abstract void draw();
}
class Circle extends Shape {
    void draw() {
        System.out.println("Drawing circle");
    }
}
class Test {
    public static void main(String[] args) {
        Shape s = new Shape();
        s.draw();
    }
}
ACannot instantiate abstract class Shape
BMethod draw() must be static
CCircle class must be abstract
DMissing return type in draw() method
Step-by-Step Solution
Solution:
  1. Step 1: Check instantiation of abstract class

    Abstract classes cannot be instantiated directly, so 'new Shape()' causes error.
  2. Step 2: Verify other options

    draw() method is correctly declared and implemented; no static needed; Circle is concrete; return type is void.
  3. Final Answer:

    Cannot instantiate abstract class Shape -> Option A
  4. Quick Check:

    Abstract classes cannot be instantiated directly [OK]
Quick Trick: Abstract classes cannot be created with new keyword [OK]
Common Mistakes:
  • Trying to instantiate abstract class
  • Thinking abstract methods must be static
  • Assuming subclass must be abstract if it implements methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes