MULTI LEVEL INHERITANCE IN JAVA PART 3 in Hindi Lecture 62
//Multi-Level Inheritance in Java Inheritance-----Inheritance means to inherit the properties that is data members and methods of base class to the derived class.Base class is also known as parent class(or super class) and derived class is also known as child class(or subclass).The various types of inheritance are----- Base_class | | Derived_ class The extends keyword------The extends keyword is used to inherit the propertise(data and method) of base class into derived class. Example---- class A { //method and data members } class B extends A { //access method and data members of base class //own new method and data members of derived class } class example { public static void main(String args[]) { B obj=new B(); obj.methodname(); } } Multilevel Inheritance----There is base class and from that there is one derived class that is child1 and it act as base class for another derived class that is child2 derived class. Base_class1 | | Derived_ class1 | | Derived_class2 //Multilevel Inheritance in Java class examp1 { public int a=50,b=30,c; public void add() { System.out.println("add of values"); c=a+b; } } class examp2 extends examp1 { public void sub() { System.out.println("sub of values"); c=a-b; } } class examp3 extends examp2 { public void display() { System.out.println("a="+a); System.out.println("b="+b); System.out.println("c="+c); } } class example1 { public static void main(String args[]) { examp3 obj=new examp3(); obj.add(); obj.display(); obj.sub(); obj.display(); } }
Download
0 formatsNo download links available.