#4 most askedVery commonEasyCore Java & OOP
Abstract class vs interface
New to Core Java & OOP? Learn it from scratch firstInheritance vs Composition β
π’ Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.When would you use an abstract class instead of an interface in modern Java?
π€ Answer it out loud, then check yourself
Say your answer as if the interviewer is listening (30β90 seconds). Then reveal what a strong answer covers and tick what you said.
interface Shape { double area(); default String describe() { return "area " + area(); } }
abstract class Base implements Shape {
protected final String name; // shared state needs a class
Base(String name) { this.name = name; }
}
class Circle extends Base {
final double r;
Circle(double r) { super("circle"); this.r = r; }
public double area() { return Math.round(Math.PI * r * r * 100) / 100.0; }
}
public class Main {
public static void main(String[] args) {
Shape s = new Circle(2);
System.out.println(s.describe());
}
}
Answer out loud first, then compare.
Want to rehearse it?Answer this to the AI interviewer and get a verdict β