Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class).
The class from which the subclass is derived is called a superclass (also a base class or a parent class).Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object.Classes can be derived from classes that are derived from classes that are derived from classes, and so on, and ultimately derived from the topmost class, Object. Such a class is said to be descended from all the classes in the inheritance chain stretching back to Object.
The idea of inheritance is simple but powerful: When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class.
In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself.A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass
ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 10 - SECTION C
A super class Record contains
names and marks of the students in two different single
dimensional arrays. Define a sub
class Highest to display the names of the students
obtaining the highest mark.
The details of the members of both
the classes are given below:
Class name : Record
Data
member/instance variable:
n[ ] : array to store names
m[ ] :
array to store marks
size : to store the number of students
Member
functions/methods:
Record(int cap) :
parameterized constructor to initialize the data
member
size = cap
void readarray() :
to enter elements in both the arrays
void display( ) :
displays the array elements
Class name:
Highest
Data
member/instance variable:
index : to
store the index
Member functions/methods:
Highest(…) : parameterized
constructor to initialize the data
members
of both the classes
void find( ) :
finds the index of the student obtaining the
highest
mark and assign it to ‘index’
void display( ) :
displays the array elements along with the names and marks of the students who have
obtained the highest mark
Assume that the
super class Record has been defined. Using the concept of
inheritance,
specify the class Highest giving
the details of the constructor(…),void find( ) and
void display( ).
No comments:
Post a Comment