Methods of Java · Introduction to Java Programming

Polymorphism with Private Methods

Watch lectures

Polymorphism with Private Methods

1. Truth (beginner — private = invisible!)

Private methods are NOT inherited → child CAN'T override (parent doesn't share!). Child same-name method is brand-new (unrelated!). No polymorphism, no @Override!

2. Proof Code (compiler proof!)

class Animal {
    private void secret() { System.out.println("animal secret"); }
    void reveal() { secret(); } // calls OWN secret (private visible here!)
}
class Dog extends Animal {
    // @Override void secret() {} // ERROR! (nothing to override — invisible!)
    void secret() { System.out.println("dog secret"); } // NEW method (not override!)
}
Animal a = new Dog();
a.reveal(); // animal secret! (parent reveal → parent secret — NOT dog's!)
// a.secret(); // ERROR! (private — invisible outside Animal!)

3. Rules (exam list!)

Private method Protected/public method
Inherited? No (invisible!) Yes
Override? No (@Override errors!) Yes (if non-static!)
Access self-class only child/package/world per modifier

4. Final Methods Bonus (related!)

final methods ARE inherited but CAN'T override (locked!). Private = invisible; final = visible-but-locked!

5. Exam Points

  • Private-no-override proof + trace — 5 marks, frequent.
  • Private vs final vs static (three no-polymorphism cases) — 5 marks, favourite combo.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Introduction to Java Programming modules