Difficulty: Easy
Correct Answer: An abstract class is a class that cannot be instantiated directly and can contain both abstract methods without bodies and concrete methods with implementations.
Explanation:
Introduction / Context:
Abstract classes are a fundamental feature in Java used to model partial implementations and common behaviour that subclasses can share. This question asks you to define what an abstract class is and to contrast it with a regular concrete class, especially in terms of instantiation and method declarations.
Given Data / Assumptions:
Concept / Approach:
An abstract class is a class declared with the abstract keyword that may contain one or more abstract methods but can also contain fully implemented concrete methods, fields, and constructors. Because an abstract class may have incomplete behaviour, the Java language forbids direct instantiation of it; you must create subclasses that provide implementations for all abstract methods before you can create objects. This makes abstract classes suitable for common base behaviour that is shared among several closely related subclasses.
Step-by-Step Solution:
Step 1: A typical abstract class might look like public abstract class Shape { public abstract void draw(); public void setColor(String c) { } } where draw is abstract and setColor is concrete.Step 2: Because Shape is abstract, you cannot write new Shape(); in your code; doing so results in a compile time error.Step 3: A concrete subclass such as class Circle extends Shape { public void draw() { } } must implement the abstract draw method to become instantiable.Step 4: Abstract classes can also define fields, constructors, and protected helper methods that subclasses reuse.Step 5: Option A correctly describes that an abstract class cannot be instantiated and can contain both abstract and concrete methods, so it is the correct answer.
Verification / Alternative check:
To verify, write a small Java program with an abstract class and attempt to create an instance directly. The compiler will issue an error stating that the abstract class cannot be instantiated. After creating a subclass that implements all abstract methods, you can instantiate the subclass, proving that abstract classes serve as incomplete templates rather than complete types for objects.
Why Other Options Are Wrong:
Option B confuses abstract classes with interfaces and incorrectly claims that abstract classes can be instantiated and cannot contain methods. Option C states that abstract classes must contain only static methods, which is not true; abstract methods themselves cannot be static. Option D claims that abstract classes cannot be extended, which contradicts their primary purpose as base classes that are meant to be subclassed.
Common Pitfalls:
One common mistake is forgetting to implement all abstract methods in a subclass and wondering why the subclass must be declared abstract. Another pitfall is using abstract classes when an interface would provide more flexibility for unrelated classes. Good design uses abstract classes when there is shared state or behaviour and interfaces when you want to specify capabilities across different class hierarchies.
Final Answer:
An abstract class is a class declared with the abstract keyword that cannot be instantiated directly and can contain both abstract methods without bodies and concrete methods with implementations.
Discussion & Comments