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

Karnaugh Maps (K-Maps) for ISC Class 12: SOP and POS Reduction Step by Step
A complete ISC Class 12 Computer Science guide to Karnaugh maps: cell numbering for 3- and 4-variable maps, grouping rules, SOP and POS reduction with fully solved examples, and the mistakes that cost marks in the board exam.

ISC Practical 2027: Sentence and Date (Vowels, Future Date, Sort by Length) – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 blended question: validate a sentence and a date, count the vowels, add that many days to the date (handling month, year and leap-year changes) and sort the words by length while keeping the original order for ties.

ISC Practical 2027: Special Date Checker (Validation and Digit Sum) – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 date question: validate a date in DD/MM/YYYY format including leap years, find the days remaining in the month and check whether its digit sum is a perfect square.