0
Which type inheritance is this ...(justification if possible reference)
interface printable{ void print(); } class A6 implements printable{ public void print(){System.out.println("Hello");} public static void main(String args[]){ A6 obj = new A6(); obj.print(); } }
2 Answers
0
Your example is not inheritance, it is implementation of interface. Inheritance is term used mainly when class extends with other class.
We can think about inheritance in interfaces if one interface extends other interface, or interface has defined constant, or default method.
interface printable {
void print();
}
interface printable2 extends printable { //interface extension
String endOfLine = "\n>>> "; //constant
default void print(String s) { //default method
System.out.println(endOfLine+s);
}
}
class A6 implements printable2 {
public void print() {
System.out.println(endOfLine+"Hello");
}
public static void main(String args[]) {
A6 obj = new A6();
obj.print();
obj.print( "Hi there" );
}
}
0
As mutiple inheritance is not available in java im using this interface as the second class(not actual class) as only one method I have created the object of the class rather than object of the interface ,Can I conculde the above program as a Multiple inheritance?