Inheritance in Java for ISC Class 12: super, Method Overriding and Solved Programs
ISC Class 12 Computer Science notes on inheritance in Java: superclass and subclass, the extends and super keywords, protected members, method overriding, types of inheritance, and a fully solved board-style program.

Section C of the ISC Computer Science theory paper regularly has an inheritance question: you are given a superclass and asked to write the subclass. It is a scoring question once you know the pattern. These notes explain every part of it.
What is inheritance?
Inheritance lets a new class (the subclass, or derived class) acquire the data members and methods of an existing class (the superclass, or base class). The subclass can reuse that code and add or change behaviour.
class Person { // superclass
protected String name;
protected int age;
}
class Student extends Person { // subclass
int roll; // new member
}A Student object now has name, age and roll.
Access specifiers in inheritance
- private: accessible only inside its own class. Not accessible in the subclass.
- protected: accessible in the subclass, and in the same package.
- public: accessible everywhere.
In ISC questions, the superclass members are usually declared protected so the subclass can use them directly.The super keyword
super has two uses.
1. Calling the superclass constructor. This must be the first statement in the subclass constructor:
class Student extends Person {
int roll;
Student(String n, int a, int r) {
super(n, a); // initialises name and age in Person
roll = r;
}
}2. Calling a superclass method that the subclass has overridden:
void display() {
super.display(); // prints name and age
System.out.println("Roll: " + roll); // adds the subclass details
}Method overriding
Overriding means the subclass defines a method with the same name, return type and parameters as a method in the superclass. When the method is called on a subclass object, the subclass version runs.
Overloading vs overriding
- Where: overloading happens in the same class (or a subclass); overriding needs a superclass and a subclass.
- Parameters: overloaded methods must have different parameters; an overriding method must have the same parameters.
- Decided at: overloading is resolved at compile time; overriding is resolved at run time.
Types of inheritance in Java
- Single: A → B
- Multilevel: A → B → C
- Hierarchical: A → B and A → C
Java does not allow multiple inheritance of classes (class C extends A, B is invalid). The same effect is achieved with interfaces.
Solved board-style program
Question: A superclass Product has the data members name and price, a parameterised constructor, and a method void show() that displays them. Define a subclass Sale with:
- a data member
discountPct(the discount percentage) - a parameterised constructor that also initialises the superclass members
double finalPrice(), which returns the price after the discount- an overridden
void show()that displays all the details and the final price
Assume Product is already defined. Write the class Sale only.
class Sale extends Product {
double discountPct;
Sale(String n, double p, double d) {
super(n, p); // initialise name and price
discountPct = d;
}
double finalPrice() {
return price - price * discountPct / 100;
}
void show() {
super.show(); // name and price from Product
System.out.println("Discount: " + discountPct + "%");
System.out.println("Final price: " + finalPrice());
}
}For a product priced ₹1200 with a 15% discount, finalPrice() returns 1020.0.
Write only the class that is asked for. In this type of question, writing main() or rewriting the superclass earns no extra marks and wastes time.Checklist for inheritance questions
- Write
class Sub extends Super. - Call
super(...)as the first line of the constructor, passing the superclass values. - Use the superclass's
protectedmembers directly. Do not redeclare them in the subclass. - When overriding the display method, call
super.show()(or the method the question names) first, then print the new members.
Practice questions
- What is the output if a subclass constructor does not call
super(...)and the superclass has only a parameterised constructor? - Can a subclass access a
privatemember of its superclass directly? - State one difference between
thisandsuper.
Answers:
- A compile-time error. Java tries to call the default
super(), which does not exist. - No. It can only use it through public or protected methods of the superclass.
thisrefers to the current object, whilesuperrefers to the superclass part of the object (its constructor and methods).
Continue with our ISC Class 12 Recursion Programs and practise in the solved ISC Class 12 Computer Science Sample Paper 2027.
Related Posts
Continue learning with these related articles

Passing Objects to Methods in Java for ISC Class 12 (Object as Parameter and Return Type)
ISC Class 12 Computer Science notes on object passing: passing an object as a parameter, returning an object from a method, using this to access the current object, and a fully solved board-style Distance class program.

Arrays in Java for ISC Class 11: 1-D Arrays and 2-D Matrix Programs
ISC Class 11 Computer Science notes on arrays in Java: declaring 1-D and 2-D arrays, row-major and column-major address calculation, and solved matrix programs – transpose, boundary sum, diagonal sums and matrix multiplication – for theory and practicals.

Stack, Queue and Linked List in Java for ISC Class 12 (Notes and Programs)
ISC Class 12 Computer Science notes on data structures: stacks (LIFO) and queues (FIFO) using arrays with overflow and underflow, postfix evaluation, and singly linked lists – insert, traverse, count and search – with board-style Java programs.