6. Multiple inheritance of state is not allowed:Remember that Java does not allow a class inherits two or more classes directly. To understand why multiple inheritance is not allowed, consider the following example:1234567891011121314151617181920public class A { public void methodA() { } public void foo() { }}public class B { public void methodB() { } public void foo() { }}Suppose that we want to write a class C that extends both A and B like this:12345public class C extends A, B { public void methodC() { foo(); }}As you can see, both A and B has a method called foo(), so which foo() method the class C invokes exactly? from A or B? This case is ambiguous hence Java does not allow.7. Multiple inheritance of type is allowed:This means Java does allow multiple inheritance between interfaces. For example:1234567891011public interface X { public void methodX();}public interface Y { public void methodY();}public interface Z extends X, Y { public void methodZ();}This is allowed because interfaces do not have concrete methods, thus there is no ambiguity.Likewise, we can have a class implements multiple interfaces:1234567public class Sub implements X, Y, Z { public void methodX() { } public void methodY() { } public void methodZ() { }}
if both Interface X and Interface Y has same method called methodAB what happens?
6. Multiple inheritance of state is not allowed:Remember that Java does not allow a class inherits two or more classes directly. To understand why multiple inheritance is not allowed, consider the following example:1234567891011121314151617181920public class A { public void methodA() { } public void foo() { }}public class B { public void methodB() { } public void foo() { }}Suppose that we want to write a class C that extends both A and B like this:12345public class C extends A, B { public void methodC() { foo(); }}As you can see, both A and B has a method called foo(), so which foo() method the class C invokes exactly? from A or B? This case is ambiguous hence Java does not allow.7. Multiple inheritance of type is allowed:This means Java does allow multiple inheritance between interfaces. For example:1234567891011public interface X { public void methodAB();}public interface Y { public void methodAB();}public interface Z extends X, Y { public void methodZ();}This is allowed because interfaces do not have concrete methods, thus there is no ambiguity.Likewise, we can have a class implements multiple interfaces:1234567public class Sub implements X, Y, Z { public void methodX() { } public void methodY() { } public void methodZ() { }}
package MultipleInheritanceType;public interface X { public void methodAB();}package MultipleInheritanceType;public interface Y { public void methodAB();}package MultipleInheritanceType;public interface Z extends X, Y { public void methodABC();}package MultipleInheritanceType;public class Sub implements X, Y, Z { @Override public void methodABC() { // TODO Auto-generated method stub } @Override public void methodAB() { // TODO Auto-generated method stub } /*public void methodX() { } public void methodY() { } public void methodZ() { }*/}