001package types.multipleInheritance2;
002
003/* 
004 * The "diamond of death" is not a problem in java, since multiple inheritance
005 * is only possible for interfaces, and interfaces use "virtual inheritance" and
006 * does not allow interfaces to have fields (no multiple-inheritance of state)
007 * 
008 * See
009 * http://stackoverflow.com/questions/137282/how-can-you-avoid-the-diamond-of-death-in-c-when-using-multiple-inheritance
010 * http://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html
011 */
012interface I0 {
013        public void f ();
014}
015interface I1 extends I0 { 
016        default public void g () { System.out.println ("I1.g"); }
017}
018interface I2 extends I0 {
019        default public void g () { System.out.println ("I2.g"); }
020}
021
022/* It is possible to inherit conflicting defaults, as long as you don't use them!
023 * If you comment out the definition of g in C or K below, you will get an error!
024 */
025class C implements I1, I2 { 
026        public void f () { System.out.println ("C.f"); } 
027        public void g () { System.out.println ("C.g"); } 
028}
029interface K extends I1, I2 { 
030        default public void g () { System.out.println ("I2.g"); }
031}
032public class Main {
033        public static void main (String[] args) {
034                C x = new C ();
035                x.g ();
036        }
037}