SINGLE INHERITANCE IN JAVA PART 2 in Hindi Lecture 61
//Single Inheritance in Java 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(); } } a.Single Inheritance----There is single base class and single derived class. Single Base_class | | Single Derived_ class //Single Inheritance in Java class examp1 { public int a=10,b=20,c; public void add() { c=a+b; } } class examp2 extends examp1 { public void display() { System.out.println("a="+a); System.out.println("b="+b); System.out.println("c="+c); } } class example { public static void main(String args[]) { examp2 obj=new examp2(); obj.add(); obj.display(); } }
Download
0 formatsNo download links available.