![]() ![]() Hierarchical Inheritance : – It supports to the hierarchical design of a program. ![]() Str = str.concat("U") //concatenation of strĬlass Test//create class to execute all classes ![]() Str = str.concat("Y") //concatenation of strĬlass Down3 extends Down2//sub class3 extends sub class2 Str = str.concat("I") //concatenation of strĬlass Down2 extends Down1//sub class2 extends sub class1 It allows us to build a chain of classes.Įxample : This example shows how multilevel inheritance is used in a class package First Ĭlass Down1 extends Top//sub class1 extends super class Java uses it extensively in building its class library and java also supports this concept. Multilevel Inheritance : – The use of a derived class as a super class is common requirement in object-oriented programming.("Child class method is called.!") Ĭhild ch = new Child () //create object of Child classĬh.methodParent () //calling super class methodĬh.methodChild () //calling local method Public void methodChild()//Child class method ("Parent class method is called.!") Ĭlass Child extends Parent //inherit properties of Parent class Public void methodParent()//Parent class method Single Inheritance : – When one class inherit the properties of another one class only then it is called as single inheritance.Įxample : This example shows how single inheritance is used in a class.The inheritance concept is also known as reusability classes. #Apa itu overriding dan overloading code#It is helpful for reusability of code and purpose is too used for method overriding. To describe inheritance implements and extends keywords are used. It defines a “ is-a” kind of relationship between Super class (Parent class) and Sub class (child class) in java language. When a class extends all the properties of another class it means that class inherits all non-private variables including methods and fields.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |