Inheritance, Interfaces and Polymorphism: ISC Class 12 Computer Science
Updated 15 October 2026 · Fact-checked
Inheritance lets a subclass extend a superclass, reusing and specialising its members; a subclass constructor calls super( ) first and can override methods. Polymorphism means a superclass reference can refer to subclass objects, with the right method chosen at run time. Interfaces declare behaviour that classes implement, as when a sorting class lets its user supply the comparison.
What Inheritance, Interfaces and Polymorphism is about
The syllabus asks for:
(a) Inheritance: superclass and derived (sub) classes; member access in derived classes; redefinition of variables and methods in subclasses; abstract classes; the class Object; protected visibility; subclass polymorphism and dynamic binding. Inheritance should be used only for a genuine specialisation (is-a) relationship, not merely to reuse methods.
(b) Interfaces: implementing interfaces through a class; interfaces for user-defined implementation of behaviour (for example a sorting class whose comparison is supplied by its user); the difference between the Java interface construct and the general word 'interface' meaning a class's set of method prototypes.
In the paper, Section C (answer two of three 5-mark questions) included an inheritance question in both 2024 and 2025: the superclass is described and assumed to exist, and you must write the subclass with its constructor and methods (2024: an overtime salary subclass; 2025: a passenger fare subclass). Part I may ask for a use of interfaces or a statement about constructors and overriding.
All programs on this page were compiled and run, and the outputs are shown exactly as printed.
Weightage: CISCE publishes no chapter or unit weightage for ISC Computer Science. Inheritance, Interfaces and Polymorphism is part of Section C, 12 of the 2027 syllabus and can be asked anywhere in the 70-mark Paper 1 (Part I compulsory: ten 1-mark items and a 10-mark short-answer question; Part II: two of three 10-mark questions in each of Sections A and B, and two of three 5-mark questions in Section C).Source: CISCE ISC Computer Science (868) syllabus, examination year 2027; latest Paper 1 specimen (2025) and the 2025 board paper
Key concepts
- Inheritance: extends, super and member access
class Sub extends Super { ... } makes Sub inherit Super's non-private data members and methods. Sub is a specialisation of Super (a Sale is a kind of Product record).
Key rules:
1. Java supports single inheritance of classes (one direct superclass); multilevel chains are allowed (Square → Rect → Shape → Object).
2. Constructors are not inherited. A subclass constructor must call a superclass constructor with super(arguments) as its first statement (otherwise Java inserts super( ), which fails if the superclass has no no-argument constructor). Then it initialises its own members.
3. Member access: private members of the superclass are not accessible in the subclass (use superclass methods or protected members); protected members are accessible in subclasses (and the same package); public everywhere; default within the package.
4. super.method( ) calls the superclass version of an overridden method; super.x refers to a hidden superclass variable.
5. Redefining a variable with the same name in the subclass hides the superclass one (both exist).Types of inheritance in Java classes: single, multilevel, hierarchical (several subclasses of one superclass). Multiple inheritance of classes is not allowed, but a class can implement several interfaces.
Worked example
[2] Why must super(...) be the first statement in a subclass constructor? (Understand)
Try it first, then show the solutionSolution
- The superclass part of the object must be initialised before the subclass part that may depend on it - 1 mark.
- Java requires the super( ) call (explicit or implicit) to come first; placing it later is a compile-time error - 1 mark.
Answer: Because the inherited (superclass) part of the object must be constructed before the subclass adds its own members; Java therefore insists that the call to super(...) is the first statement, otherwise compilation fails.
- Writing a Section C subclass
Pattern for the 5-mark question (superclass given, main( ) not required):
1. class Sub extends Super, with only the new data members listed for the subclass.
2. Constructor taking values for both classes: call super(...) with the superclass values first, then assign the subclass members.
3. The computing method: follow the stated conditions exactly (watch the boundaries: 'between 30 and 40, both inclusive' means >= 30 && <= 40).
4. The overriding show( ): call super.show( ) first to print the superclass details, then print the subclass details.// Single inheritance: Sale extends Product. The superclass is given; the subclass is written using // extends, a super( ) call as the first statement of its constructor, and super.show( ). class Product { protected String code, name; protected double price; Product(String c, String n, double p) { code = c; name = n; price = p; } void show() { System.out.println("Code: " + code + " Name: " + name + " Price: " + price); } } public class Sale extends Product { int qty; double disc, net; Sale(String c, String n, double p, int q) { super(c, n, p); // must be the first statement qty = q; disc = 0; net = 0; } // discount: 10% if more than 50 units, 5% for 20 to 50 units, none below 20 void compute() { double gross = price * qty; if (qty > 50) disc = 0.10 * gross; else if (qty >= 20) disc = 0.05 * gross; else disc = 0; net = gross - disc; } void show() // overrides Product's show( ) { super.show(); // superclass details first System.out.println("Quantity: " + qty + " Discount: " + disc + " Net: " + net); } public static void main(String[] args) { Sale s = new Sale("P17", "Notebook", 40, 60); s.compute(); s.show(); Sale t = new Sale("P22", "Pen", 10, 25); t.compute(); t.show(); } }Output:
Code: P17 Name: Notebook Price: 40.0 Quantity: 60 Discount: 240.0 Net: 2160.0 Code: P22 Name: Pen Price: 10.0 Quantity: 25 Discount: 12.5 Net: 237.5Working: Notebook: gross 40 × 60 = 2400; more than 50 units, 10 per cent discount 240; net 2160. Pen: 10 × 25 = 250; 20 to 50 units, 5 per cent discount 12.5; net 237.5.
(In the examination you would write only the class Sale; Product is shown here so that the program runs.)
Worked example
[2] Write the constructor of Sale, which takes code, name, price and quantity, and initialises the discount and net amount to 0. (Apply)
Try it first, then show the solutionSolution
- Sale(String c, String n, double p, int q) { super(c, n, p); - 1 mark.
- qty = q; disc = 0; net = 0; } - 1 mark.
Answer: Sale(String c, String n, double p, int q) { super(c, n, p); qty = q; disc = 0; net = 0; }
- Overriding, abstract classes and the Object class
Method overriding: a subclass defines a method with the same name, parameter list and return type as a superclass method, replacing it for subclass objects. (Overloading, by contrast, uses different parameter lists in the same class.) A subclass can still reach the superclass version with super.method( ).
Abstract class: declared abstract; cannot be instantiated; may contain abstract methods (declared without a body, ending with a semicolon) as well as ordinary methods and constructors. A concrete subclass must override all abstract methods. Use it for a general concept (Shape) whose details (area) differ for each kind.
Class Object: the root of all Java classes; every class extends Object directly or indirectly. Its methods include toString( ), equals( ) and hashCode( ). Overriding toString( ) controls what println(object) prints.
final: a final method cannot be overridden; a final class cannot be extended.
Worked example
[2] Distinguish between method overloading and method overriding. (Understand)
Try it first, then show the solutionSolution
- Overloading: same name, different parameter lists, usually in the same class; resolved at compile time - 1 mark.
- Overriding: subclass redefines a superclass method with the same signature and return type; resolved at run time (dynamic binding) - 1 mark.
Answer: Overloading gives one class several methods of the same name with different parameter lists, chosen at compile time; overriding redefines an inherited method with the same signature in a subclass, chosen at run time according to the object's class.
- Polymorphism and dynamic binding
Subclass polymorphism: a superclass reference can refer to an object of any subclass: Shape s = new Circle(2);. Through s you can call only methods declared in Shape, but the version that runs is the one belonging to the object's actual class: dynamic (late) binding, decided at run time.
This lets one loop handle many kinds of object: an array Shape[ ] holding circles, rectangles and squares can compute each area with s.area( ).
Casting objects: upcasting (subclass to superclass) is automatic. Downcasting (superclass reference to subclass type) needs an explicit cast and works only if the object really is of that subclass; instanceof checks this first.
// Abstract class, method overriding, dynamic binding, the Object class and toString( ). abstract class Shape { protected String label; Shape(String label) { this.label = label; } abstract double area(); // no body: every concrete subclass must define it public String toString() // overrides Object's toString( ) { return label + " with area " + Math.round(area() * 100) / 100.0; } } class Circle extends Shape { double r; Circle(double r) { super("Circle"); this.r = r; } double area() { return Math.PI * r * r; } } class Rect extends Shape { double l, b; Rect(double l, double b) { super("Rectangle"); this.l = l; this.b = b; } double area() { return l * b; } } class Square extends Rect // multilevel: Square -> Rect -> Shape -> Object { Square(double s) { super(s, s); label = "Square"; } } public class Shapes { public static void main(String[] args) { Shape[] list = { new Circle(2), new Rect(3, 4), new Square(5) }; double total = 0; for (Shape s : list) { System.out.println(s); // toString( ) chosen at run time total += s.area(); // dynamic binding: the object's own area( ) runs } System.out.println("Total area = " + Math.round(total * 100) / 100.0); Object o = list[2]; System.out.println(o instanceof Rect); Rect r = (Rect) o; // downcast: allowed because o really refers to a Square System.out.println(r.l + " " + r.b); } }Output:
Circle with area 12.57 Rectangle with area 12.0 Square with area 25.0 Total area = 49.57 true 5.0 5.0Area of the circle: π × 2² ≈ 12.57; total 12.57 + 12 + 25 = 49.57. Square inherits Rect's area( ) and fields, so the downcast (Rect) o works.
Worked example
[2] Shape s = new Square(5); System.out.println(s.area()); Which area( ) runs, and why? (Analyse)
Try it first, then show the solutionSolution
- Square does not define area( ), so it inherits Rect's version - 1 mark.
- Dynamic binding chooses the method from the object's actual class (Square → Rect's area), giving 25.0, even though s is declared as Shape - 1 mark.
Answer: Rect's area( ), inherited by Square, runs and returns 25.0: the method is chosen at run time by the object's class (dynamic binding).
- Interfaces
An interface (Java construct) declares a set of method headers (and constants) that a class promises to provide:
interface Order { boolean before(Pupil a, Pupil b); }
class ByMarksDesc implements Order { public boolean before(Pupil a, Pupil b) { return a.marks > b.marks; } }Rules: interface methods are public and (traditionally) abstract; a class that implements an interface must define all its methods as public; a class can implement several interfaces (Java's way of achieving multiple inheritance of type); an interface reference can refer to any implementing object.
Uses of interfaces:
1. Let the user of a reusable class supply part of the behaviour (the comparison in a sorting class, as below).
2. Multiple inheritance of type: a class can be several things at once.
3. Define abstract data types with several implementations (for example a Stack interface implemented by an array or a linked list).
4. Abstraction: users depend on what operations exist, not how they are coded.The word 'interface' in general also means the set of public method prototypes through which other code uses a class; that is not the same as the Java interface keyword.
// An interface lets the user of a reusable sorting class supply the comparison rule. interface Order { boolean before(Pupil a, Pupil b); // true if a should come before b } class Pupil { String name; int marks; Pupil(String n, int m) { name = n; marks = m; } } class ByMarksDesc implements Order { public boolean before(Pupil a, Pupil b) { return a.marks > b.marks; } } class ByName implements Order { public boolean before(Pupil a, Pupil b) { return a.name.compareTo(b.name) < 0; } } public class SortRecords { // insertion sort that works for ANY ordering rule passed in static void sort(Pupil[] p, Order rule) { for (int i = 1; i < p.length; i++) { Pupil key = p[i]; int j = i - 1; while (j >= 0 && rule.before(key, p[j])) { p[j + 1] = p[j]; j--; } p[j + 1] = key; } } static void print(Pupil[] p) { for (Pupil x : p) System.out.print(x.name + "(" + x.marks + ") "); System.out.println(); } public static void main(String[] args) { Pupil[] p = { new Pupil("Ishaan", 78), new Pupil("Aditi", 91), new Pupil("Meher", 85), new Pupil("Dev", 64) }; sort(p, new ByMarksDesc()); print(p); sort(p, new ByName()); print(p); } }Output:
Aditi(91) Meher(85) Ishaan(78) Dev(64) Aditi(91) Dev(64) Ishaan(78) Meher(85)The same sort( ) method sorts by marks (descending) or by name, depending on which Order object it receives.
Worked example
[1] Can one Java class implement two interfaces? Give the class header for a class Robot that implements interfaces Movable and Chargeable. (Understand)
Try it first, then show the solutionSolution
- Yes: a class may implement any number of interfaces, listed after implements and separated by commas: class Robot implements Movable, Chargeable { ... }, defining every method of both as public - 1 mark.
Answer: Yes. class Robot implements Movable, Chargeable { ... } (Robot must define all the methods of both interfaces as public). This is how Java gives multiple inheritance of type.
Inheritance, Interfaces and Polymorphism in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Inheritance (is-a)
Imagine a hospital system with a general Person record (name, age) and a Doctor record that has everything a Person has plus a specialisation and fee.
How should the classes be related, and what should Doctor's constructor do first?
Try it first, then show the solutionSolution
- A doctor is a person: class Doctor extends Person.
- Doctor's constructor calls super(name, age) first, then sets specialisation and fee.
Answer: Doctor extends Person, reusing its members; its constructor begins with super(name, age).
Memory hook: Is-a means extends; build the parent first.
Dynamic binding
Suppose a music app has a 'play' button that works for songs, podcasts and audiobooks, each handled differently.
How does one button call the right behaviour?
Try it first, then show the solutionSolution
- Each type overrides a play( ) method declared in a common superclass or interface.
- At run time the object's own play( ) is called: dynamic binding.
Answer: Through polymorphism: a common reference calls play( ), and Java runs the version belonging to the actual object.
Memory hook: One call, the right behaviour.
Interface as a contract
Imagine a charging socket standard: any phone that follows the standard can be charged by any compatible charger.
How is this like a Java interface?
Try it first, then show the solutionSolution
- The standard specifies what must be provided, not how the phone is built inside.
- Classes that implement an interface promise to provide its methods, so any code using the interface can work with them.
Answer: A Java interface is a contract like a socket standard: implementing classes guarantee the methods, and users rely only on the contract.
Memory hook: Interface says what, class says how.
Topics in this chapter
Inheritance, Interfaces and Polymorphism: syntax and key facts
- Subclass declaration
- class Sub extends Super { ... }
- One direct superclass.
- Subclass constructor
- Sub(args) { super(superArgs); own = ...; }
- super( ) first.
- Overriding show
- void show() { super.show(); print own members; }
- Superclass details first.
- Abstract
- abstract class A { abstract double area(); }
- Cannot instantiate; subclasses must define.
- Interface
- interface I { type m(params); } class C implements I { public type m(params) { ... } }
- A class may implement many interfaces.
How the board asks Inheritance, Interfaces and Polymorphism
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Section C subclass [5] | Superclass described and assumed; write the subclass with constructor(...), a calculation method and show( ). | extends; super(...) first; exact conditions; super.show( ) then own details; do not rewrite the superclass. |
| Theory [1]-[2] | Use of interfaces; overloading versus overriding; abstract classes; protected access; dynamic binding. | One precise point each, with a code fragment if helpful. |
| Output questions | Which method runs for a superclass reference to a subclass object; constructor call order. | Overridden methods follow the object; fields and static methods follow the reference type. |
| Programs [10] | Class hierarchies with abstract methods or interfaces used polymorphically. | Define the abstract or interface methods in every concrete class; use an array of superclass references. |
Tricks to remember Inheritance, Interfaces and Polymorphism
Short memory aids. Say each one aloud once, then use it on a question the same day.
E-S-S
Extends in the header, Super( ) first in the constructor, Super.show( ) first in show( ).
Use it when: Section C subclass.
Overload = same class, new list; Override = new class, same signature
Load more versions here; ride over the parent's version.
Use it when: Overloading versus overriding.
Object decides, reference restricts
The reference type decides which methods you may call; the object decides which version runs.
Use it when: Dynamic binding.
Inheritance, Interfaces and Polymorphism: board-level solved questions
Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Root class · 1 mark · MCQBoard level
Which class is the superclass of every class in Java?
(a) Main
(b) Object
(c) Class
(d) System
Try it first, then show the solutionSolution
- Every class extends Object directly or indirectly.
- Its methods such as toString( ) are available to all objects.
Answer: (b) Object.
Example 2: Protected access · 1 mark · Very short answerBoard level
Can a subclass in another package access a protected data member of its superclass?
Try it first, then show the solutionSolution
- protected allows access within the package and in subclasses.
- So yes, through inheritance.
Answer: Yes (through inheritance); private members, however, are not accessible.
Example 3: Assertion-reason: abstract class · 1 mark · Assertion-reasonHarder board level
Assertion (A): An object of an abstract class cannot be created with new.
Reason (R): An abstract class may contain methods that have no body.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Try it first, then show the solutionSolution
- A is true: new Shape("x") does not compile.
- R is true and is the reason: an object could otherwise call a method with no implementation.
Answer: (a) Both A and R are true and R is the correct explanation of A.
Example 4: Subclass for a sales record · 5 marks · Long answerHarder board level
[5] A superclass Product (code, name, price; a parameterised constructor; void show( )) is defined. Define a subclass Sale with data members qty, disc and net; a constructor for both classes' members; void compute( ) giving a 10 per cent discount on price × qty for more than 50 units, 5 per cent for 20 to 50 units (both inclusive) and none otherwise, and the net amount; and void show( ) that displays all details. (Create)
Try it first, then show the solutionSolution
- class Sale extends Product { int qty; double disc, net; (1)
- Constructor: super(c, n, p); then qty = q; disc = 0; net = 0; (1)
- compute( ): gross = price * qty; if qty > 50 disc = 0.10 * gross; else if qty >= 20 disc = 0.05 * gross; else disc = 0; (1)
- net = gross - disc; (1)
- show( ): super.show( ); then print qty, disc, net. (1)
Answer: See the compiled Sale class; for 60 notebooks at Rs 40 the discount is 240.0 and net 2160.0; for 25 pens at Rs 10 the discount is 12.5 and net 237.5.
Example 5: Polymorphic total · 5 marks · Long answerHOTS / competency
[5] Using the abstract class Shape with abstract double area( ), write classes Circle and Rect, and a loop over a Shape[ ] array that prints each shape and the total area for a circle of radius 2, a 3 × 4 rectangle and a square of side 5 (Square extends Rect). (Create)
Try it first, then show the solutionSolution
- abstract class Shape with label, constructor, abstract double area( ), toString( ) using area( ).
- Circle extends Shape: super("Circle"); area( ) returns Math.PI * r * r.
- Rect extends Shape: area( ) returns l * b; Square extends Rect calling super(s, s).
- Loop for (Shape s : list) { System.out.println(s); total += s.area(); }
- Output: areas 12.57, 12.0, 25.0; total 49.57 (program output).
Answer: See the compiled Shapes program: Circle 12.57, Rectangle 12.0, Square 25.0, total 49.57.
Example 6: Interface-based sorting · 10 marks · Long answerHOTS / competency
[10] Define an interface Order with boolean before(Pupil a, Pupil b); classes ByMarksDesc and ByName implementing it; and a class with static void sort(Pupil[ ] p, Order rule) using insertion sort with rule.before( ). Show the order of Ishaan 78, Aditi 91, Meher 85, Dev 64 under each rule. Explain why an interface is useful here. (Create)
Try it first, then show the solutionSolution
- interface Order { boolean before(Pupil a, Pupil b); } and class Pupil with name and marks.
- ByMarksDesc: return a.marks > b.marks; ByName: return a.name.compareTo(b.name) < 0; both methods public.
- sort( ): insertion sort; while (j >= 0 && rule.before(key, p[j])) shift; place key.
- By marks: Aditi(91) Meher(85) Ishaan(78) Dev(64).
- By name: Aditi(91) Dev(64) Ishaan(78) Meher(85).
- Usefulness: the sorting code is written once; the user supplies the comparison, which only they know (field and order), exactly the motivation in the syllabus.
Answer: By marks: Aditi(91) Meher(85) Ishaan(78) Dev(64); by name: Aditi(91) Dev(64) Ishaan(78) Meher(85) (program output). The interface lets one sort method work with any user-supplied ordering.
Case-study practice (Section D style)
Read the situation, then answer every part. In the board paper this is a 6-mark question split into 1 + 2 + 1 + 2 marks.
Library members (case-based)
A superclass Member has name and memberId with a constructor and show( ). A subclass Student adds className and finePerDay; a subclass Teacher adds department. Both override show( ).
(i) · 1 mark
What type of inheritance is this?
Answer
Answer: Hierarchical inheritance (two subclasses of one superclass).
1 mark.
(ii) · 2 marks
Write the header and constructor of Student.
Answer
Answer: class Student extends Member { String className; double finePerDay; Student(String n, int id, String c, double f) { super(n, id); className = c; finePerDay = f; } }
1 for extends, 1 for super first.
(iii) · 1 mark
If Member m = new Teacher(...); m.show(); which show( ) runs?
Answer
Answer: Teacher's show( ) (dynamic binding).
1 mark.
(iv) · 2 marks
Can Java let Student extend both Member and another class Borrower? What is the alternative?
Answer
Answer: No, a class has only one direct superclass; Borrower could be made an interface that Student implements.
1 + 1.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
[2] Overloading versus overriding. (2 marks)
| Step | Marks |
|---|---|
| Overloading defined (same name, different parameters, compile time). | 1 |
| Overriding defined (subclass, same signature, run time). | 1 |
[5] Subclass Sale. (5 marks)
| Step | Marks |
|---|---|
| extends and subclass data members. | 1 |
| Constructor with super(...) first. | 1 |
| Discount conditions with correct boundaries. | 1 |
| Net amount. | 1 |
| show( ) with super.show( ). | 1 |
[10] Interface Payable with two implementations. (10 marks)
| Step | Marks |
|---|---|
| Interface declaration. | 1 |
| Salaried implementing pay( ) as public. | 2 |
| Hourly with overtime rule. | 3 |
| Array of interface references. | 2 |
| Loop printing pays and total. | 2 |
Where students lose marks in Inheritance, Interfaces and Polymorphism
The slips examiners see most often, and what to write instead.
Mistake: Missing extends or super( ), or super( ) not first
CISCE examiners' comments, 2024 and 2025: 'Keyword extends missing in the derived class declaration', 'Super class constructor not called, or called after initialising derived class variables', 'Omitted or misused extends and super'.
Do this: Header: class Sub extends Super. Constructor: first line super(...) with the superclass values.
Usually costs: 1-2 marks.
Mistake: Not calling the superclass show( ), or rewriting the superclass
CISCE examiners' comments: 2024 'Super class variables not printed; wrote only the base class'; 2025 'Redefined the base class unnecessarily' and 'Did not call superclass show( ) from subclass'.
Do this: Write only the subclass; in show( ) call super.show( ) and then print the new members.
Usually costs: 1-2 marks.
Mistake: Wrong range conditions
CISCE examiners' comments, 2024: conditions such as '< for >, 30>salary<40, or salary>=30 || salary<=40'.
Do this: 'Between 30 and 40 inclusive' is hours >= 30 && hours <= 40; test the highest band first in an if-else-if ladder.
Usually costs: 1 mark.
Mistake: Defining an interface instead of stating its use
CISCE examiners' comments, 2024: candidates 'Wrote the definition of Java or of an interface instead of a use of interface'.
Do this: Answer the question asked: a use is, for example, achieving multiple inheritance or letting users supply behaviour.
Usually costs: 1 mark.
Practice questions on Inheritance, Interfaces and Polymorphism
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · Very short answerBoard level
Which keyword is used to inherit a class?
Hint
Not implements.
Answer
extends
Q2 · 1 mark · Very short answerBoard level
Which keyword makes a class follow an interface?
Hint
Not extends.
Answer
implements
Q3 · 1 mark · Very short answerBoard level
Can an abstract class have a constructor?
Hint
Used by subclasses.
Answer
Yes; it runs when a subclass object is created (via super(...)).
Q4 · 1 mark · Very short answerHarder board level
What is dynamic binding?
Hint
Run time.
Answer
Choosing, at run time, which overridden method to execute according to the actual class of the object.
Q5 · 2 marks · Short answerHarder board level
[2] What is printed? class A { void hi() { System.out.print("A "); } } class B extends A { void hi() { System.out.print("B "); super.hi(); } } ... A x = new B(); x.hi();
Hint
B's version, which calls A's.
Answer
B A (B's overriding hi( ) runs and then calls the superclass version).
Q6 · 2 marks · Short answerHarder board level
[2] Why should inheritance not be used just to reuse a few methods?
Hint
is-a.
Answer
Inheritance should model a genuine is-a (specialisation) relationship; otherwise the subclass inherits members that make no sense for it and the design becomes confusing. Reuse without is-a is better done by using an object of the other class (composition).
Q7 · 5 marks · Long answerHOTS / competency
[5] A superclass Worker has name and basic (double) with a parameterised constructor and show( ). Define a subclass Wages with days and total; a constructor; void calc( ) where total = basic × days + a bonus of Rs 2000 if days exceed 25 (Rs 1000 for 20 to 25 days, none below 20); and show( ). Compute total for basic 800, days 26.
Hint
super first; boundaries.
Answer
class Wages extends Worker { int days; double total; Wages(String n, double b, int d) { super(n, b); days = d; total = 0; } void calc() { total = basic * days; if (days > 25) total += 2000; else if (days >= 20) total += 1000; } void show() { super.show(); System.out.println(days + " " + total); } } For 800 × 26 = 20800 + 2000 = 22800.0 (checked by running the code).
Q8 · 10 marks · Long answerHOTS / competency
[10] Define an interface Payable with double pay( ); classes Salaried (monthly salary) and Hourly (rate and hours, with 1.5 × rate for hours above 160) implementing it; and a main( ) that stores both in a Payable[ ] array and prints each pay and the total. Use salary 45000 and an hourly worker at Rs 250 for 170 hours.
Hint
Overtime 10 hours.
Answer
interface Payable { double pay(); } class Salaried implements Payable { double sal; ... public double pay() { return sal; } } class Hourly implements Payable { double rate; int hrs; ... public double pay() { return hrs <= 160 ? rate * hrs : rate * 160 + 1.5 * rate * (hrs - 160); } } main( ): Payable[] p = { new Salaried(45000), new Hourly(250, 170) }; loop printing p[i].pay( ) and summing. Pays: 45000.0 and 40000 + 3750 = 43750.0; total 88750.0 (checked by running the code).
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.Does Java allow multiple inheritance of classes?Show answer
No; a class can implement several interfaces instead.
2.First statement of a subclass constructor?Show answer
super(...) (explicit or implicit).
3.Can an abstract class be instantiated?Show answer
No.
4.Root of the class hierarchy?Show answer
Object.
5.Which method runs for A x = new B(); x.m(); if B overrides m?Show answer
B's m( ).
Best order to study it
- extends, super, access modifiers and constructor chaining.
- Section C subclass pattern with practice.
- Overriding, abstract classes, Object and toString( ).
- Polymorphism and dynamic binding; casting objects.
- Interfaces: syntax, rules and uses.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- class Sub extends Super: inherits non-private members; one direct superclass.
- Subclass constructor: super(...) first.
- super.show( ) calls the superclass version.
- protected: accessible in subclasses; private: not.
- Overriding: same signature in subclass, chosen at run time; overloading: different parameters.
- abstract class: no objects; abstract methods must be defined by concrete subclasses.
- interface: method contract; implements; many per class; methods public.
Inheritance, Interfaces and Polymorphism: frequently asked questions
Do I write the superclass and main( ) in the Section C inheritance question?
No. The question tells you that the superclass is already defined and that main( ) and the algorithm are not required, so write only the subclass.
Can interfaces have method bodies?
In newer Java versions interfaces may have default and static methods, but for ISC treat interface methods as abstract headers that implementing classes must define.
Are constructors inherited?
No. A subclass must define its own constructors and call a superclass constructor with super(...).
Based on: CISCE ISC 2027 Computer Science (868) syllabus; CISCE ISC Computer Science (868) Paper 1 specimen question paper and answer key (latest specimen, 2025); CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2025; CISCE Analysis of Pupil Performance, ISC Computer Science (868), 2024