- An abstract class is a partly built parent. It can have fields, constructors and finished methods, plus abstract methods its children must write. A class can extend only one.
- An interface is a capability: "can send notifications", "can be compared". It has no instance fields or constructors. Since Java 8 it can also contain default and static methods. A class can implement many.
import java.util.*;
interface Notifier {
String send(String msg);
default String sendAll(String... msgs) {
StringJoiner out = new StringJoiner(" ");
for (String m : msgs) out.add(send(m));
return out.toString();
}
}
abstract class Member {
protected final String name;
Member(String name) { this.name = name; }
abstract double fee();
String describe() { return name + " pays " + fee(); }
}
class Student extends Member implements Notifier {
Student(String name) { super(name); }
double fee() { return 200; }
public String send(String msg) { return "[SMS to " + name + "] " + msg; }
}
class Faculty extends Member {
Faculty(String name) { super(name); }
double fee() { return 500; }
}
public class OopDemo {
public static void main(String[] args) {
List<Member> members = List.of(new Student("Ravi"), new Faculty("Dr. Rao"));
for (Member m : members) System.out.println(m.describe());
System.out.println(new Student("Ravi").sendAll("Fee due", "Lab at 2"));
}
}Ravi pays 200.0
Dr. Rao pays 500.0
[SMS to Ravi] Fee due [SMS to Ravi] Lab at 2How to decide
- The types share state and code and are clearly "a kind of" the parent (Student and Faculty are kinds of Member): use an abstract class.
- Unrelated classes need the same ability (a Student, a Club and a Hostel could all be a Notifier): use an interface.
- Unsure? Start with an interface. It keeps classes free to extend something else later.
The viva answer in one breath
"An abstract class can hold state and constructors and supports single inheritance; an interface defines a contract, supports multiple implementation and, since Java 8, can have default methods. I use an abstract class for shared state and an interface for a shared capability." Practise more in UniCircle interview prep: object-oriented programming.
#java#oop#interfaces#abstract classes
Sources and further reading
Practise this as an interview question
Written by the UniCircle team, checked by an editor on 22 Oct 2026. It is not official policy of any university. Exam patterns and rules change; confirm dates and rules on the official website.
