Why Multiple&Hybrid Inheritances-Java Doesn’t Support-How to solve it
Multiple and Hybrid inheritance
There are other two inheritance concepts multiple and hybrid inheritance.These are not directly supported in java.It is not possible for a child class to inherit two parent class properties through inheritance.In order to achieve this two techniques we have to implement interfaces concepts.This can be achieved through the interface concept, called multiple inheritance.The combination of any two inheritance is called hybrid inheritance.
multiple inheritance represantation
Interface
Interfaces,like abstract classes and methods,have a lot of functionality.Two keywords are used interface and implements.one of the differences between class and interface is that an interface cannot be instantiated,the keyword new can create only an instance of class.
sample program-Interface Example program
interface A { void show1(); } interface B { void show2(); } class C implements A,B { public void show1() { System.out.println("____________________________________"); System.out.println("object can be created this class"); System.out.println("called concrete class"); System.out.println("show1 method declaration"); System.out.println("____________________________________"); } public void show2() { System.out.println("show2 method declaration"); System.out.println("____________________________________"); } } class Mminter { public static void main(String a[]) { C obj=new C(); obj.show1(); obj.show2(); } }
👍🏻
ReplyDelete👍🏻
ReplyDeleteNice 👍
ReplyDelete