Skip to content
Computer ScienceISC Class 12 · Inheritance, Interfaces and Polymorphism

Inheritance, super, Abstract Classes and Polymorphism (ISC Class 12 Computer Science)

Updated 17 October 2026 · Draft, not yet fact-checked

Inheritance lets a derived class extend a super class, reusing its members and adding or redefining others. super refers to the parent (constructor call super(...) must come first). A method redefined with the same signature overrides the parent's, and the version run depends on the object's actual class (dynamic binding). An abstract class cannot be instantiated.

Dog and Cat extend abstract Animal and override sound(); the object's real class (Dog) decides which version runs, and Animal itself cannot be created.

Illustration drawn for QuestionBuddy.

Understand Inheritance, super, Abstract Classes and Polymorphism

Inheritance. class Dog extends Animal makes Animal the super (base) class and Dog the derived (sub) class. Dog gets the accessible members of Animal and can add its own. Use inheritance for a real specialisation ("a Dog is an Animal"), not merely to borrow a few methods. Java allows one super class (single inheritance for classes); every class ultimately extends class Object, which supplies methods such as toString() and equals().

Member access. private members are not visible in the derived class; protected members are visible in the derived class (and the same package); public is visible everywhere. Constructors are not inherited.

super. super(args) as the first statement of a constructor calls the super class constructor; if it is not written, the no-argument super constructor runs first automatically. So when objects are created, constructors run from the top class down. super.method() calls the parent's version of an overridden method, and super.var reaches a hidden parent variable.

Redefinition. A derived class may redefine a method with the same name, parameters and return type (overriding) and may declare a variable with the same name as a parent variable (the parent's variable is hidden, not replaced). Overriding differs from overloading: overloading has the same name with different parameters in one class (compile-time), overriding replaces an inherited method (run time).

Subclass polymorphism and dynamic binding. A super class reference can hold a derived object: Shape s = new Sq(4);. A method call through s runs the version of the object's actual class (dynamic binding), but a variable access uses the reference's declared type, and only members known to the declared type can be called without a cast. A downcast (Sq) s is needed to use derived-only members, and a wrong cast gives ClassCastException at run time.

Abstract classes. abstract class Shape { abstract double area(); } may contain abstract methods (no body) and ordinary methods. It cannot be instantiated; a concrete derived class must implement every abstract method or be declared abstract itself. A reference of the abstract type can still point to derived objects.

Interfaces, which also give polymorphism, are in the next topic.

Inheritance, super, Abstract Classes and Polymorphism: key facts

Inheritance syntax
  • class Derived extends Base
  • One super class only
  • Constructors are not inherited
  • Every class extends Object
The derived class is-a Base.
Constructor order
  • Super constructor runs first
  • super(args) must be the first statement
  • No explicit call means super() is called implicitly
  • Order: top class down
Output of print statements follows this order.
Overriding versus overloading
  • Overriding: same signature in derived class, chosen at run time
  • Overloading: same name, different parameters, chosen at compile time
  • Fields are hidden, not overridden
Dynamic binding applies to methods only.
Access levels
privateown class only
protectedderived classes and same package
publiceverywhere
Abstract class cannot be instantiated
A concrete subclass implements all abstract methods.

How to answer Inheritance, super, Abstract Classes and Polymorphism questions

Use this routine for inheritance output questions.

  1. 1Draw the class hierarchy and mark each overridden method.
  2. 2For object creation, list the constructors in the order super class first, then derived.
  3. 3For a method call, find the actual class of the object and use its version (or the nearest parent version).
  4. 4For a variable access, use the declared type of the reference.
  5. 5Check what the declared type allows: calling a derived-only method needs a cast.
  6. 6Write the output exactly; a trailing space after print is part of it.

Inheritance, super, Abstract Classes and Polymorphism in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Different employees, one pay method

Suppose an Employee class has a method pay() that returns the base salary, and Manager extends Employee and overrides pay() to add an allowance. A list of Employee references holds both kinds.

Which pay() runs for a Manager object stored in an Employee reference?

Try it first, then show the solutionSolution
  1. Dynamic binding picks the version by the actual object.
  2. The object is a Manager, so Manager's pay() runs.

Answer: Manager's overriding pay().

Memory hook: The object decides, not the label.

Abstract template

Suppose a Shape class declares an abstract area() and every shape must supply its own formula.

Can a program write new Shape()?

Try it first, then show the solutionSolution
  1. An abstract class cannot be instantiated.
  2. Only concrete subclasses such as Sq can be created.

Answer: No, it is a compile-time error.

Memory hook: An abstract idea has no object of its own.

Tricks to remember Inheritance, super, Abstract Classes and Polymorphism

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Parents first

    Constructors run from the top class down, so parent output comes first.

    Use it when: Constructor chaining output.

  • Object picks the method

    Methods follow the real object; fields follow the declared type.

    Use it when: Dynamic binding questions.

  • Is-a test

    Say "Dog is an Animal"; if the sentence is false, do not inherit.

    Use it when: Designing inheritance.

  • Abstract = unfinished

    An abstract class has an unfinished method; subclasses must finish it.

    Use it when: Abstract class questions.

Inheritance, super, Abstract Classes and Polymorphism: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Keyword for inheritance · 1 mark · MCQBoard level

The keyword used to derive a class from a super class is
(a) implements (b) extends (c) inherits (d) super

Try it first, then show the solutionSolution
  1. A class inherits from another class using extends; implements is for interfaces.

Answer: (b) extends

Example 2: Constructor chaining · 3 marks · Short answerHarder board level

Write the output:

class A {
    A()      { System.out.print("A "); }
    A(int x) { System.out.print("A" + x + " "); }
}
class B extends A {
    B()      { System.out.print("B "); }
    B(int y) { super(y); System.out.print("B" + y + " "); }
}
// in main
new B();
new B(7);
Try it first, then show the solutionSolution
  1. new B(): no explicit super call, so A() runs first and prints "A ", then B() prints "B ". (1 mark)
  2. new B(7): super(y) calls A(7), which prints "A7 ", then B prints "B7 ". (1 mark)
  3. Output: A B A7 B7 (each followed by a space). (1 mark)

Answer: A B A7 B7

Example 3: Overriding and dynamic binding · 4 marks · Short answerHarder board level

Write the output:

class Shape {
    double area()  { return 0; }
    String name()  { return "Shape"; }
}
class Sq extends Shape {
    double s;
    Sq(double s) { this.s = s; }
    double area()  { return s * s; }
    String name()  { return "Square"; }
}
class Circ extends Shape {
    double r;
    Circ(double r) { this.r = r; }
    double area()  { return 3.0 * r * r; }
}
// in main
Shape[] a = { new Sq(4), new Circ(2), new Shape() };
for (int i = 0; i < a.length; i++)
    System.out.println(a[i].name() + " " + a[i].area());
Try it first, then show the solutionSolution
  1. Sq overrides both methods: Square and 16.0. (1.5 marks)
  2. Circ overrides area only: area = 3.0 x 2 x 2 = 12.0, and name() is inherited, giving Shape. (1.5 marks)
  3. The plain Shape gives Shape and 0.0. (1 mark)

Answer: Square 16.0
Shape 12.0
Shape 0.0

Example 4: Hidden variable and super · 3 marks · Short answerHarder board level

Write the output:

class P {
    int v = 10;
    int get() { return v; }
}
class Q extends P {
    int v = 20;
    int get() { return v + super.v; }
}
// in main
P o = new Q();
System.out.println(o.v + " " + o.get() + " " + ((Q) o).v);
Try it first, then show the solutionSolution
  1. o.v uses the declared type P, so it is 10. (1 mark)
  2. o.get() runs Q's get: v is 20 and super.v is 10, giving 30. (1 mark)
  3. ((Q) o).v is Q's variable, 20. Output: 10 30 20. (1 mark)

Answer: 10 30 20

Example 5: Case: abstract bonus · 4 marks · Case-basedHOTS / competency

Suppose a bank program has:

abstract class Account {
    abstract double bonus();
    void show() { System.out.println("Bonus " + bonus()); }
}
class Savings extends Account {
    double bal;
    Savings(double b) { bal = b; }
    double bonus() { return bal * 0.25; }
}

(i) Is Account a = new Account(); valid? (1 mark)
(ii) Write the output of Account a = new Savings(2000); a.show();. (2 marks)
(iii) What happens if Savings does not define bonus()? (1 mark)

Try it first, then show the solutionSolution
  1. (i) No: an abstract class cannot be instantiated; compile-time error.
  2. (ii) show() is inherited and calls bonus() dynamically, so Savings' version runs: 2000 x 0.25 = 500.0. Output: Bonus 500.0
  3. (iii) Compile-time error, because Savings would be a concrete class with an unimplemented abstract method; it must implement bonus() or be declared abstract.

Answer: (i) invalid (ii) Bonus 500.0 (iii) compile-time error unless Savings is abstract

Where students lose marks in Inheritance, super, Abstract Classes and Polymorphism

The slips examiners see most often, and what to write instead.

  • Mistake: Child output before parent output

    The super class constructor runs first.

    Wrong working

    new B() prints B A

    Right working

    new B() prints A B

    Do this: Trace constructors from the top.

    Usually costs: 1 mark

  • Mistake: Using the declared type for a method call

    Overridden methods are chosen by the actual object.

    Wrong working

    Shape s = new Sq(4); s.area() gives 0

    Right working

    Shape s = new Sq(4); s.area() gives 16.0

    Do this: Look at what follows new.

    Usually costs: 1 mark

  • Mistake: super call not first

    super(...) must be the first statement of a constructor.

    Wrong working

    B(int y) { print("B"); super(y); }

    Right working

    B(int y) { super(y); print("B"); }

    Do this: Put super(...) on the first line.

    Usually costs: 1 mark

Exam tips

  • Draw the hierarchy first and mark overridden methods.
  • Give the is-a sentence to justify an inheritance design.
  • State dynamic binding in one line when a base reference holds a derived object.
  • Write extends for classes and implements for interfaces.
  • For abstract classes mention that they cannot be instantiated and that subclasses implement the abstract methods.

Practice questions on Inheritance, super, Abstract Classes and Polymorphism

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    A class that cannot be instantiated is called
    (a) final class (b) abstract class (c) static class (d) derived class

    Hint

    It may have methods with no body.

    Answer

    (b) abstract class

  2. Q2 · 2 marks · Short answerBoard level

    What does the protected access specifier allow? Compare it with private.

    Hint

    Think of derived classes.

    Answer

    A protected member can be used inside its own class, in derived classes and in classes of the same package. A private member is accessible only inside its own class, so a derived class cannot use it directly.

  3. Q3 · 2 marks · Short answerHarder board level

    Write the output:

    class Vehicle {
        String move() { return "moves"; }
    }
    class Car extends Vehicle {
        String move() { return "drives and " + super.move(); }
    }
    // in main
    System.out.println(new Car().move());
    Hint

    super.move() is the parent's version.

    Answer

    Car's move() runs and adds the parent's text: drives and moves

  4. Q4 · 4 marks · Short answerHarder board level

    Write the output:

    class A {
        void f(int x) { System.out.print("A.int "); }
    }
    class B extends A {
        void f(double x) { System.out.print("B.double "); }
        void f(int x)    { System.out.print("B.int "); }
    }
    // in main
    A a = new B();
    B b = new B();
    b.f(1);
    b.f(1.0);
    a.f(1);

    Say which methods are overloaded and which overridden.

    Hint

    f(int) is redefined; f(double) is new.

    Answer

    b.f(1) picks f(int): B.int. b.f(1.0) picks f(double): B.double. a.f(1) is a call to f(int); the object is a B, so the overriding version runs: B.int. Output: B.int B.double B.int. In B, f(int) overrides A.f(int); f(int) and f(double) in B are overloaded.

  5. Q5 · 4 marks · Case-basedHOTS / competency

    Given class Animal { void speak() {} } and class Dog extends Animal { void fetch() {} }, state for each statement whether it is valid, a compile-time error or a run-time error: (i) Animal a = new Dog(); a.speak(); (ii) Animal a = new Dog(); a.fetch(); (iii) Animal a = new Dog(); ((Dog) a).fetch(); (iv) Dog d = (Dog) new Animal();

    Hint

    The declared type decides what can be called; the object decides what a cast can succeed on.

    Answer

    (i) Valid; Dog inherits speak(). (ii) Compile-time error: the type Animal has no fetch(). (iii) Valid: the cast is correct because the object is a Dog. (iv) Compiles because Dog is a subtype, but fails at run time with ClassCastException, since the object is only an Animal.

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Which keyword derives a class from another?Show answer

    extends.

  2. 2.Which class is the parent of every class in Java?Show answer

    Object.

  3. 3.Can an abstract class be instantiated?Show answer

    No.

  4. 4.What must be the first statement when super(...) is used?Show answer

    It must be the first statement of the constructor.

  5. 5.What is dynamic binding?Show answer

    The version of an overridden method is chosen at run time by the actual object.

  6. 6.Is a private member inherited for direct use?Show answer

    No, it is not accessible in the derived class.

Inheritance, super, Abstract Classes and Polymorphism: frequently asked questions

What is the difference between method overloading and overriding?

Overloading is several methods with the same name and different parameters in one class, resolved at compile time; overriding is redefining an inherited method with the same signature, resolved at run time.

What is the use of the super keyword?

It calls the super class constructor with super(args) and accesses overridden methods or hidden variables of the super class with super.name.

What is an abstract class?

A class declared abstract that may contain abstract methods; it cannot be instantiated and is meant to be extended by classes that complete it.

What is the class Object?

The root of the Java class hierarchy; every class inherits from it, so every object has methods such as toString() and equals().