/* In Kotlin interfaces, functions can have optional, default implementations that are inherited by classes that implement them. Since classes can implement multiple interfaces (but not extend multiple classes), this creates a multiple inheritance problem. Java, since version 8, also allow default functions to be implemented in interfaces with the keyword 'default'. There are proposals to change C# in a similar way. These languages tend to develop in parallel: Java is already very different from when Kotlin was first created. Assignment: Java, Kotlin and C# don't allow multiple inheritance of classes, so do it anyway (in C#). */ interface I1 { fun f():Int { return 1; } fun g() { println("I1.g"); } fun h(x:Int):Int; // this is what really belongs in an interface } interface I2 { fun f():Int { return 2; } fun g() { println("I2.g"); } } /* A class that implements both interfaces must override f and g, else get compiler error: "class 'A' must override public open fun f(): Int defined in I1 because it inherits multiple interface methods of it" */ class A : I1, I2 { override fun f():Int { return 3; } // when we override, we can also select which one to inherit override fun g() { super.g(); } // differ to I2.g() override fun h(x:Int):Int { return x*x; } } fun main(argv:Array) { var m:I1 = A(); println(m.f()); m.g(); } // compile: kotlinc multi.kt -include-runtime -d multi.jar // run: java -jar multi.jar