सीधे मुख्य सामग्री पर जाएं

#51 What is Inheritance in Java | Types of Inheritance in Java | Inheritance क्या होता है ?

package com.sudhirtheindian2.java123;

public class Inheritance {
public static void main(String[] args) {

// What is inheritance in java ?

// When one class access the property of another class is called inheritance

// When we construct a new class from existing class in such
// a way that the new class access all the features
// & properties of existing class called inheritance

// 1 In java extends keyword is used to perform inheritance
// 2 We cannot access private member of class through inheritance
// 3 It provides code reusability
// 4 a sub class contains all the features of super class so we
// should create the object of sub class
// 5 method overriding only possible through inheritance


// Types of Inheritance

// 1 Simple or Single Inheritance
// one super class & one sub class

// syntax

// super class --->> sub class


// class A{ // super class
//
// }
// class B extends A{ // sub class
//
//
// }




// 2 Multi Level Inheritance
// In multilevel inheritance we have only one super class &
// multiple sub class called multilevel inheritance

// one super class & multiple sub class

// super----> sub1----> sub2---->


// class Super{
//
//
// }
// class sub1 extends Super{
//
// }
// class sub2 extends sub1{
//
// }






// 3 Multiple Inheritance

// java does not support multple inheritance

// syntax
// super--> super--> sub




// 4 Hierarchial Inheritance

// one super class and multipel sub class but
// all the sub class connected directly to super class

// super class--->> sub1
// super class--->> sub2
// super class--->> sub3


}
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट