Module-2 Inheritance
Module-2 Inheritance
• Since compile-time errors are better than runtime errors, Java renders compile-
time error if you inherit 2 classes. So whether you have same method or
different, there will be compile time error.
Hybrid Inheritance
• Hybrid (mixture) is made of more than one thing. In
Java, the hybrid inheritance is the composition of
two or more types of inheritance.
A conceptual depiction of the Triangle class
• You can specify only one superclass for any subclass that you create. Java
does not support the inheritance of multiple superclasses into a single subclass.
• Since width and height are declared private, they are accessible only
by other members of their own class. Subclasses have no access to them.
• Remember that a class member that has been declared private will
remain private to its class. It is not accessible by any code outside its
class, including subclasses.
•The second is used to access a member of the superclass that has been
hidden by a member of a subclass.
Using super to Call Superclass Constructors
super(parameter-list);
class student
{ class marks extends student
int rollno; {
String name; int total;
marks(int r, String n, int t)
student(int r, String n) {
{ super(r,n);
rollno = r; total = t;
name = n; }
} void dispdatam()
void dispdatas() {
{ dispdatas();
System.out.println("Rollno = " + System.out.println("Total = " + total);
rollno); }
System.out.println("Name = " + }
name);
}
}
Cont..
class Gfg{
static final int CAPACITY = 4;