Prashnikaप्रश्निका
Code
About
Computer ScienceClass 12

Inheritance, Interfaces and Polymorphism - ISC Class 12 Computer Science Questions with Answers

44 past-paper questions on Inheritance, Interfaces and Polymorphism from ISC Class 12 Computer Science papers (2026-2017), newest first, in full. Questions 1-20 are on this page, 20 to a page. Tap "Show answer" under a question to see its answer. The syllabus covers Inheritance, Member access in derived classes, Redefinition of variables and methods, Abstract classes, Class Object, Protected visibility, Subclass polymorphism and dynamic binding and Interfaces in Java and more.

44questions
9years
2026newest
20265 questions
5 marks · ProgramOpen: A superclass Course has been defined to store the basic details of a course…

Write the program described below.

A superclass Course has been defined to store the basic details of a course. Define a subclass Internship to store internship-related information and calculate total earnings. The details of both the members of the class are given below:
Class name:Course
Data members/instance variables:
title:to store the course title
duration:to store the course duration in months
Methods/Member functions:
Course(...):parameterised constructor to assign values to its data members
void show( ):to display the course details
Class name:Internship
Data members/instance variables:
company:to store company name
stipend:to store the monthly allowance
totalEarnings:to store the total earnings
Methods/Member functions:
Internship(...):parameterised constructor to assign values to data members of both the classes
void calculate( ):to calculate the total earnings as: (stipend $\times$ duration)
void show( ):to display course and internship details
Assume that the superclass Course has been defined. Using the concept of Inheritance, specify the class Internship, giving details of constructor(...), void calculate( ) and void show( ). The super class, main function and algorithm need NOT be written.
Show answer

Answer

class Internship extends Course
{
    String company;
    double stipend;
    double totalEarnings;

    Internship(String t, int d, String c, double s)
    {
        super(t, d);
        company = c;
        stipend = s;
        totalEarnings = 0.0;
    }

    void calculate()
    {
        totalEarnings = stipend * duration;
    }

    void show()
    {
        super.show();
        System.out.println("Company: " + company);
        System.out.println("Stipend: " + stipend);
        calculate();
        System.out.println("Total Earnings: " + totalEarnings);
    }
}
Explanation: Internship extends Course. Its constructor calls super(t, d) to initialise the inherited title and duration, then initialises its own data members. calculate() computes totalEarnings as stipend × duration (duration is inherited from Course). show() calls super.show() to display the course details, then displays the internship details and total earnings. Tested (run for real, with a stub Course class and main): for duration=6 and stipend=5000.0, calculate() correctly gave Total Earnings = 30000.0.
1 mark · Assertion-reasonOpen: In Java, an abstract class is created for the purpose of inheritance.

Study the Assertion and Reason and choose the correct option.

Assertion: In Java, an abstract class is created for the purpose of inheritance.

Reason: An abstract class can be instantiated.

  • (a)Both Assertion and Reason are true and Reason is the correct explanation for Assertion.
  • (b)Both Assertion and Reason are true but Reason is not the correct explanation for Assertion.
  • (c)Assertion is true and Reason is false.
  • (d)Both Assertion and Reason are false.
Show answer

Answer

Correct option: (c)

Answer: (c) Assertion is true and Reason is false. Assertion: An abstract class in Java is indeed created for the purpose of being extended (inherited), so that its subclasses provide concrete implementations of its abstract methods — this is true. Reason: 'An abstract class can be instantiated' is false — an abstract class can never be instantiated directly using 'new'; only its concrete (non-abstract) subclasses can be instantiated.
1 mark · Assertion-reasonOpen: In Java, a subclass can override a method of its superclass by defining a…

Study the Assertion and Reason and choose the correct option.

Assertion: In Java, a subclass can override a method of its superclass by defining a method with the same name and same signature.

Reason: If the subclass calls the overridden method without using the super keyword, the subclass’s own version of the method will get called, leading to recursion.

  • (a)Both Assertion and Reason are true and Reason is the correct explanation for Assertion.
  • (b)Both Assertion and Reason are true but Reason is not the correct explanation for Assertion.
  • (c)Assertion is true and Reason is false.
  • (d)Both Assertion and Reason are false.
Show answer

Answer

Correct option: (b)

Answer: (b) Both Assertion and Reason are true but Reason is not the correct explanation for Assertion. Assertion: In Java, a subclass overrides a superclass method by defining a method with the same name and same signature — this is the correct definition of method overriding, so it is true. Reason: If a subclass method calls the overridden method by its own name (without 'super'), dynamic method dispatch causes the subclass's own version to be invoked again — which can lead to (self-)recursion. This is also a true statement, but it describes a runtime consequence of overriding rather than explaining the rule/definition of overriding stated in the Assertion. Hence Reason does not explain Assertion.
1 mark · Assertion-reasonOpen: An interface in Java contains abstract and non-abstract methods.

Study the Assertion and Reason and choose the correct option.

Assertion: An interface in Java contains abstract and non-abstract methods.

Reason: All methods in an interface must be implemented by any class that extends this interface.

  • (a)Both Assertion and Reason are true and Reason is the correct explanation for Assertion.
  • (b)Both Assertion and Reason are true but Reason is not the correct explanation for Assertion.
  • (c)Assertion is true and Reason is false.
  • (d)Both Assertion and Reason are false.
Show answer

Answer

Correct option: (d)

Answer: (d) Both Assertion and Reason are false. In standard ISC Java curriculum, an interface contains only abstract method declarations (non-abstract methods belong to abstract classes). Furthermore, a class implements an interface (using the 'implements' keyword), it does not extend it. Hence, both Assertion and Reason are false.
5 marks · ProgramOpen: A superclass Hotel has been defined to store the details of a hotel. Define a…

Write the program described below.

A superclass Hotel has been defined to store the details of a hotel. Define a subclass Customer to calculate the total bill for a customer as per the following criteria:
Room typeAdditional Amount
Executive10% of room rent
Suite20% of room rent
The details of the members of both the classes are given below: Class name : Hotel Data members/instance variables: hname : to store hotel name roomrent : to store the rent per day Methods/Member functions: Hotel(...) : parameterised constructor to assign values to its data members void show( ) : to display hotel details Class name : Customer Data members/instance variables: cname : to store customer name days : to store the number of days of stay type : to store the room type surcharge : to store the additional amount amt : to store the total amount Methods/Member functions: Customer(...) : parameterised constructor to assign values to data members of both the classes void compute( ) : to calculate the surcharge based on the room type as given above. Also, to calculate the total amount as: (room rent + surcharge) × days void show( ) : to display hotel and customer details Assume that the superclass Hotel has been defined. Using the concept of Inheritance, specify the class Customer, giving details of constructor(...), void compute( ) and void show( ). The super class, main function and algorithm need NOT be written.
Show answer

Answer

class Customer extends Hotel
{
    String cname;
    int days;
    String type;
    double surcharge;
    double amt;

    Customer(String h, double r, String c, int d, String t)
    {
        super(h, r);
        cname = c;
        days = d;
        type = t;
        surcharge = 0.0;
        amt = 0.0;
    }

    void compute()
    {
        if (type.equalsIgnoreCase("Executive"))
        {
            surcharge = 0.10 * roomrent;
        }
        else if (type.equalsIgnoreCase("Suite"))
        {
            surcharge = 0.20 * roomrent;
        }
        else
        {
            surcharge = 0.0;
        }

        amt = (roomrent + surcharge) * days;
    }

    void show()
    {
        super.show();
        System.out.println("Customer Name: " + cname);
        System.out.println("Days of Stay: " + days);
        System.out.println("Room Type: " + type);
        System.out.println("Surcharge per day: " + surcharge);
        System.out.println("Total Amount: " + amt);
    }
}
Explanation: Customer extends Hotel. The constructor invokes super(h, r) to initialise superclass members and initialises its own data members. compute() calculates surcharge based on room type and computes total amount as (roomrent + surcharge) * days. show() calls super.show() and displays customer details.
202515 questions
1 mark · Short answerOpen: Study the given two classes below and identify the error if any, in the given…

Answer the following question.

Study the given two classes below and identify the error if any, in the given code.
class Vehicle
{
    protected String colour;
    protected String registration;
    public Vehicle(String c, String r)
    {
        colour = c;
        registration = r;
    }
    public void show()
    {
        System.out.println("Colour:" + colour);
        System.out.println("Registration number:" + registration);
    }
}

class Car extends Vehicle
{
    private double weight;
    private String model;
    public Car(String model, double weight, String colour, String registration)
    {
        this.model = model;
        this.weight = weight;
        super(colour, registration);
    }
    public void show()
    {
        super.show();
        System.out.println("Car Model name = " + model);
        System.out.println("Car body weight = " + weight);
    }
}
Show answer

Answer

The error is in the Car constructor: the call super(colour, registration) is not the first statement of the constructor. In Java, a call to super() must always be the first statement in a constructor, so this gives a compile time error ("call to super must be first statement in constructor").
5 marks · ProgramOpen: A superclass Train has been defined to store the details of a train for booking…

Write the program described below.

A superclass Train has been defined to store the details of a train for booking tickets. Define a subclass Booking to compute the total cost of the tickets based on the number of passengers and any discount for group bookings. The details of the members of both the classes are given below: Class name : Train Data members/instance variables: trainName : to store the name of the train trainNumber : to store the train number ticketPrice : to store the price of a single ticket in decimal Methods/Member functions: Train(...) : parameterised constructor to assign values to data members void displayDetails( ) : to display the train details Class name : Booking Data members/instance variables: numPassengers : to store the number of passengers for booking groupDiscount : to store the group discount percentage totalCost : to store the total cost after applying the group discount in decimal Methods/Member functions: Booking(...) : parameterised constructor to assign values to data members of both the classes void calCost( ) : to calculate the cost as per the formula (ticket price * numPassengers), apply a group discount of 10% if numPassengers is greater than 5 and calculate the total cost with discount, if any void displayDetails( ) : to display the train details, number of passengers, group discount and the total cost with discount, if any Assume that the superclass Train has been defined. Using the concept of Inheritance, specify the class Booking giving the details of the constructor(...), void calCost( ) and void displayDetails( ). The superclass, main function and algorithm need NOT be written.
Show answer

Answer

class Booking extends Train
{
    int numPassengers;
    double groupDiscount;
    double totalCost;

    Booking(String tn, int tno, double tp, int np)
    {
        super(tn, tno, tp);
        numPassengers = np;
        groupDiscount = 0.0;
        totalCost = 0.0;
    }

    void calCost()
    {
        totalCost = ticketPrice * numPassengers;
        if (numPassengers > 5)
        {
            groupDiscount = 10.0;
            totalCost = totalCost - (totalCost * groupDiscount / 100);
        }
    }

    void displayDetails()
    {
        super.displayDetails();
        System.out.println("Number of Passengers: " + numPassengers);
        System.out.println("Group Discount: " + groupDiscount + "%");
        System.out.println("Total Cost: " + totalCost);
    }
}
Explanation: Booking extends Train, so it inherits trainName, trainNumber and ticketPrice. Its constructor calls super(...) to initialise the inherited members and then sets its own. calCost() computes the base cost (ticketPrice * numPassengers) and applies a 10% group discount only if numPassengers > 5. displayDetails() calls super.displayDetails() to show the train details, then prints the booking-specific details. Tested (with a stub Train class and main): for ticketPrice=1500.0 and numPassengers=7 (>5), the program correctly computes groupDiscount=10.0% and totalCost = 1500*7 - 10% = 9450.0.
1 mark · Short answerOpen: In the given code snippet, which feature of object-oriented programming concept…

Answer the following question.

In the given code snippet, which feature of object-oriented programming concept is being exhibited by the substring( ) method?
String s1 = "sandwich"; 
System.out.println(s1.substring(4)); 
System.out.println(s1.substring(1,4));
Show answer

Answer

It exhibits method overloading (compile time/static polymorphism): the class String has two versions of substring( ) - substring(int) and substring(int, int) - with the same name but a different number of parameters.
1 mark · Short answerOpen: What will happen if void show( ) in subclass Car is given access specifier as…

Answer the following question.

What will happen if void show( ) in subclass Car is given access specifier as private?
Show answer

Answer

Java does not allow an overriding method to reduce the visibility of the method it overrides. Since Vehicle's show() is public, making Car's show() private is not a valid override and causes a compile time error: "show() in Car cannot override show() in Vehicle; attempting to assign weaker access privileges; was public".
1 mark · MCQOpen: In single inheritance, which one of the following keywords should NOT be used.

Choose the correct option.

In single inheritance, which one of the following keywords should NOT be used.
  • (a)extends
  • (b)this
  • (c)super
  • (d)implements
Show answer

Answer

Correct option: d

Answer: (d) implements. Single inheritance between classes in Java uses the extends keyword, with this and super available for use inside the subclass. implements is used to implement an interface, not for single class inheritance.
1 mark · Short answerOpen: What will happen if data members of super class are made private instead of…

Answer the following question.

What will happen if data members of super class are made private instead of protected?
Show answer

Answer

If the data members of the super class are made private, they become inaccessible directly in the subclass. The subclass would no longer be able to refer to colour and registration by name in its own methods; it would have to use public getter/setter (accessor/mutator) methods of the super class to access or change them.
1 mark · MCQOpen: Consider the following code segment: class Car extends Vehicle implements…

Choose the correct option.

Consider the following code segment:
class Car extends Vehicle implements Fourwheeler
{.......}
Which of the following statements are valid for the given code? I. Vehicle is a super class and Fourwheeler is an interface. II. Interface cannot have abstract methods. III. Keyword extends applies to class and keyword implements applies to interface.
  • (a)Only I and II
  • (b)Only II and III
  • (c)Only I and III
  • (d)Only II
Show answer

Answer

Correct option: (c)

Answer: (c) Only I and III I is true: Vehicle is the superclass and Fourwheeler is an interface. III is true: 'extends' is used for inheriting a class and 'implements' is used for implementing an interface. II is false: an interface CAN have abstract methods (by default all its methods are abstract, unless declared default/static).
5 marks · Case basedOpen: Consider the class definitions and answer the questions: Complete the missing…

Answer the following questions.

Consider the class definitions and answer the questions:
(a)[3]
Complete the missing parts of the code given below:
class SI ?1? Account     
{                            
    double sINT; 
    public SI (double sP, double sR, double sT) 
    { 
        ?2?                                           
        sINT = 0; 
    } 
    public void Interest() 
    {   
        sINT = (P * R * T) / 100;  
    } 
    public void display() 
    { 
        ?3? //invoke display( ) of base class                
        Interest(); 
        System.out.println("Simple Interest=" + sINT);      
    } 
} // class ends
(b)[2]
Answer the following questions, based on the above code: (i) Name the base class and derived class (ii) Write the prototype of the base class constructor.
Show answer

Answer (a)

Blanks: extends; super(sP, sR, sT);; super.display();

?1? extends ?2? super(sP, sR, sT); ?3? super.display();

Answer (b)

(i) Base class = Account, Derived class = SI. (ii) Prototype of the base class constructor: Account(double P, double R, double T)
5 marks · ProgramOpen: A superclass Flight has been defined to store the details of a flight. Define a…

Write the program described below.

A superclass Flight has been defined to store the details of a flight. Define a subclass Passenger to calculate the fare for a passenger. The details of the members of both the classes are given below: Class name : Flight Data members/instance variables: flightno : to store the flight number in string dep_time : to store the departure time in string arr_time : to store the arrival time in string basefare : to store the base fare in decimal Methods/Member functions: Flight(...) : parameterised constructor to assign values to the data members void show( ) : to display the flight details Class name : Passenger Data members/instance variables: id : to store the ID of the passenger name : to store the name of the passenger tax : to store the tax to be paid in decimal tot : to store the total amount to be paid in decimal Methods/Member functions: Passenger(...) : parameterised constructor to assign values to the data members of both the classes void cal( ) : to calculate the tax as 5% of base fare and total amount (base fare + tax) void show( ) : to display the flight details along with the passenger details and total amount to be paid Assume that the super class Flight has been defined. Using the concepts of Inheritance, specify the class Passenger giving the details of constructor(...), void cal( ) and void show( ). The super class, main function and algorithm need NOT be written.
Show answer

Answer

class Passenger extends Flight
{
    int id;
    String name;
    double tax, tot;

    Passenger(String fn, String dt, String at, double bf, int i, String n)
    {
        super(fn, dt, at, bf);
        id = i;
        name = n;
        tax = 0.0;
        tot = 0.0;
    }

    void cal()
    {
        tax = 0.05 * basefare;
        tot = basefare + tax;
    }

    void show()
    {
        super.show();
        System.out.println("Passenger ID: " + id);
        System.out.println("Passenger Name: " + name);
        System.out.println("Tax: " + tax);
        System.out.println("Total Amount: " + tot);
    }
}
Explanation: Passenger extends Flight. Its constructor calls super(...) to initialise the inherited Flight data members, then sets its own. cal() computes tax as 5% of basefare (inherited from Flight) and the total as basefare+tax. show() calls super.show() to print the flight details, then prints the passenger details and total. Tested (with a stub Flight class and main) - correctly prints flight details, tax = 250.0 and total = 5250.0 for a base fare of 5000.0.
5 marks · Case basedOpen: Answer the following questions related to object-oriented programming: In Java…

Answer the following questions.

Answer the following questions related to object-oriented programming:
(a)[2]
In Java, polymorphism is exhibited in two different ways. Identify them in the code snippets given in Column A and Column B?
Column AColumn B
Shapes myShape = new Shapes(); myShape.area(); myShape.area(5); myShape.area(6.0, 1.2); myShape.area(6, 2);class Vehicle { void drive() { System.out.println("Vehicle is moving"); } } class Bus extends Vehicle { void drive() { System.out.println("Bus is running safely"); } } public static void main() { Bus b = new Bus(); b.drive(); }
(b)[1.5]
Differentiate between the keywords this and super(...) with respect to constructor.
(c)[1.5]
Base class Student and derived class ICSEStudent are illustrated as: Student $\rightarrow$ ICSEStudent. Similarly, show the classes Shapes, Triangle, TwoD_Shapes, Sphere, ThreeD_Shapes exhibiting inheritance at multi-levels, depending on the type of shapes.
Show answer

Answer (a)

Column A shows compile-time (static) polymorphism / method overloading: the class Shapes has several area() methods with the same name but different parameter lists (no arguments, one int, two doubles, two ints), and the correct one is chosen at compile time based on the arguments passed. Column B shows run-time (dynamic) polymorphism / method overriding: Bus overrides Vehicle's drive() method, and calling b.drive() on a Bus object invokes Bus's version - the method that actually runs is decided at run time based on the object's actual class.

Answer (b)

this(...) is used inside a constructor to call another constructor of the same class (constructor chaining within the class), and must be the first statement in the constructor. super(...) is used inside a constructor to call a constructor of the immediate base (parent) class, so the base class part of the object is initialised first; it must also be the first statement in the constructor.

Answer (c)

Shapes -> TwoD_Shapes -> Triangle (one branch, for two-dimensional shapes) Shapes -> ThreeD_Shapes -> Sphere (another branch, for three-dimensional shapes) Both branches show multilevel inheritance, similar to Student -> ICSEStudent.
1 mark · Short answerOpen: All methods declared in the interface are abstract. Where will the body of…

Answer the following question.

All methods declared in the interface are abstract. Where will the body of these abstract methods be defined?
Show answer

Answer

The body of an interface's abstract methods is defined in the class that implements the interface; that class must provide (override) the implementation for every abstract method of the interface.
1 mark · Assertion-reasonOpen: An abstract class can contain abstract as well as non-abstract methods. Given…

Study the Assertion and Reason and choose the correct option.

Assertion: An abstract class can contain abstract as well as non-abstract methods.

Reason: Abstract classes are meant to provide complete implementation of all types of methods in its sub class.

Given below are two statements marked Assertion and Reason. Read the two statements carefully and choose the correct option.
  • (a)Both Assertion and Reason are true and Reason is the correct explanation for Assertion.
  • (b)Both Assertion and Reason are true but Reason is not the correct explanation for Assertion.
  • (c)Assertion is true and Reason is false.
  • (d)Both Assertion and Reason are false.
Show answer

Answer

Correct option: (c)

Answer: (c) Assertion is true and Reason is false. An abstract class can indeed contain both abstract and non-abstract (concrete) methods - Assertion is true. However an abstract class is NOT meant to provide complete implementation of all methods for its subclass; rather it deliberately leaves the abstract methods unimplemented for the subclass to define - Reason is false.
1 mark · MCQOpen: interface A { final static int x = 5; abstract void abc( ); } interface B {…

Choose the correct option.

interface A 
{ 
    final static int x = 5; 
    abstract void abc( ); 
} 

interface B 
{ 
    final static int y = 5; 
    abstract void abc( ); 
}
Assume that class Check implements interfaces A and B, how many times the method abc( ) will be defined in class Check ?
  • (a)Twice
  • (b)Once
  • (c)Compile time error
  • (d)Runtime error
Show answer

Answer

Correct option: b

Answer: (b) Once. Both interfaces A and B declare the same abstract method signature abc( ). When class Check implements both, providing one concrete definition of abc( ) satisfies the abstract method requirement of both interfaces, so it is defined only once.
5 marks · Case basedOpen: Fix the following keywords at the right places: extends, super, protected…

Answer the following questions.

Fix the following keywords at the right places: extends, super, protected, abstract, implements
(a)[1]
class D1 ______ i1, i2            
{              
}
(b)[1]
_________ void printInfo( );
(c)[1]
class S1 
{             
} 
class D2 ______ S1 
{             
}
(d)[1]
class S2 
{ 
    public void show( ) 
    {       
    } 
} 
class D3 extends S2 
{ 
    public void show( ) 
    { 
        ____.show( );                        
    } 
}
(e)[1]
// Package X
class S3 {
    ______ int data;
}

// Package Y
class D4 extends S3 {
    public void calc() {
        data = 120 * 3;
    }
}
Show answer

Answer (a)

Blanks: implements

implements

Answer (b)

Blanks: abstract

abstract

Answer (c)

Blanks: extends

extends

Answer (d)

Blanks: super

super

Answer (e)

Blanks: protected

protected

About Inheritance, Interfaces and Polymorphism

Inheritance, Interfaces and Polymorphism is a unit of the ISC Class 12 Computer Science syllabus.

The syllabus lists these topics: Inheritance, Member access in derived classes, Redefinition of variables and methods, Abstract classes, Class Object, Protected visibility, Subclass polymorphism and dynamic binding, Interfaces in Java and Implementing interfaces.

Prashnika has 44 past-paper questions on Inheritance, Interfaces and Polymorphism, from papers of 2017-2026, asked in 9 different years. By kind: Program (15), Short answer (14), MCQ (7) and Assertion-reason (5). They carry between 1 and 5 marks, and most are worth 1 mark.

To practise, use the paper generator, which can build a practice paper from this chapter.

Common questions

What topics are in Inheritance, Interfaces and Polymorphism in ISC Class 12 Computer Science?

The syllabus lists Inheritance, Member access in derived classes, Redefinition of variables and methods, Abstract classes, Class Object, Protected visibility, Subclass polymorphism and dynamic binding, Interfaces in Java and Implementing interfaces.

How many questions on Inheritance, Interfaces and Polymorphism are in ISC Class 12 Computer Science past papers?

Prashnika has 44 questions on Inheritance, Interfaces and Polymorphism, from papers of 2017-2026 (board, specimen, improvement and practice papers together).

What kinds of questions are asked on Inheritance, Interfaces and Polymorphism?

By kind: Program (15), Short answer (14), MCQ (7) and Assertion-reason (5).

Questions on other pages on Inheritance, Interfaces and Polymorphism