PRASHNIKAप्रश्निका
Back to the paper

A superclass Course has been defined to store the basic details of a course. Define a subclass…

Computer Science20265 marksProgram
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.

Answer

Answer

AI
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.
Inheritance, Interfaces and Polymorphism

From ISC 2026 Improvement Computer Science Paper 1, question 10.