c2cedge
C, Java & Python · C — Java Essentials

Java: Object-Oriented Programming

OOP is Java's core, and interviewers drill the distinctions: overloading vs overriding, interface vs abstract class, and the four pillars in Java terms.

Test weight: Very high (Java)Skill: OOP fluencyDifficulty: Medium

Java is built around classes and objects, and OOP questions are guaranteed. You need the four pillars — encapsulation, inheritance, polymorphism, abstraction — in concrete Java terms, plus the distinctions that trip people up: method overloading vs overriding, and interface vs abstract class.

Overloading vs overriding

Overloading: same method name, different parameter lists, in the same class — resolved at compile time (static polymorphism). Overriding: a subclass redefines an inherited method with the same signature — resolved at runtime based on the actual object (dynamic polymorphism).

Inheritance and overriding
class Animal { String sound() { return "..."; } }
class Dog extends Animal {
    @Override String sound() { return "Woof"; }   // overriding
}
Animal a = new Dog();
System.out.println(a.sound());  // "Woof" — runtime picks Dog's method
⚡ The edge
  • Overloading is compile-time (same name, different parameters); overriding is runtime (subclass redefines the same signature). Calling a.sound() on an Animal reference holding a Dog runs Dog's version — dynamic dispatch.
  • Interface vs abstract class: an interface is a pure contract a class implements (a class can implement many); an abstract class can have partial implementation and state, but a class extends only one. Java allows multiple interfaces but single class inheritance.
Worked example
What's the difference between method overloading and overriding?
  1. Overloading: several methods with the same name but different parameters in one class; the compiler picks which to call (compile-time).
  2. Overriding: a subclass provides a new body for an inherited method with the same signature; the JVM picks based on the actual object (runtime).
  3. Overloading is static polymorphism; overriding is dynamic polymorphism.
Worked example
When do you use an interface vs an abstract class?
  1. Use an interface to define a contract (what a class can do) that many unrelated classes can implement, and to get multiple inheritance of type.
  2. Use an abstract class when you want to share common code/state among closely related subclasses, with some methods left abstract.
  3. A class implements many interfaces but extends only one (abstract) class.
⚠ Watch out
  • Overloading vs overriding is the #1 OOP mix-up — different params (compile-time) vs same signature in a subclass (runtime).
  • Java has no multiple inheritance of classes (diamond problem) — but a class can implement multiple interfaces.
  • final methods can't be overridden, static methods are hidden not overridden, and private methods aren't inherited.
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms