Single Inheritance is the simple inheritance of all, When a class extends another class(Only one class) then we call it as Single inheritance. The below diagram represents the singleinheritance in java where Class B extends only one class Class A. Here Class B will be the Sub class and Class A will be one and only Super class.
Single Inheritance Example
Single Inheritance Example
public class ClassA { public void dispA() { System.out.println("disp() method of ClassA"); } } public class ClassB extends ClassA { public void dispB() { System.out.println("disp() method of ClassB"); } public static void main(String args[]) { //Assigning ClassB object to ClassB reference ClassB b = new ClassB(); //call dispA() method of ClassA b.dispA(); //call dispB() method of ClassB b.dispB(); } }
Output :
disp() method of ClassA disp() method of ClassB
No comments:
Post a Comment