Interface is a set of constant values and methods defined. The interface is a special abstract class.
ava is a single-class inheritance.
java interfaces can inherit multiple interfaces.
Class does not allow multiple inheritance The main reason is that if A and B inherits C, b and c and D at the same time there is a method, how to determine the inheritance A one do that?
But the interface does not exist such problems, all interfaces are abstract methods inherited anyone indifferent, so the interface can inherit multiple interfaces.
When the interface inherits multiple interfaces, even if multiple interfaces with the same method, but the final implementation of the interface class can only achieve a method and a method @Override, so call it
There will be no problem
A plurality of interfaces can not inherit a class in java, but may be implemented by a plurality of interface inheritance interfaces. Specific code as follows:
1 public interface LanguageBeharvior { 2 public void language(); 3 }
1 public interface SpeakBeharvior { 2 public void speak(); 3 }
1 public interface PersonBeharvior extends LanguageBeharvior,SpeakBeharvior{ 2 3 }
1 public class Person implements PersonBeharvior{ 2 3 @Override 4 public void language() { 5 6 System.out.println("汉语"); 7 } 8 9 @Override 10 public void speak() { 11 12 System.out.println("人会说话"); 13 } 14 15 }
1 public class Main { 2 public static void main(String[] args) { 3 Person person = new Person(); 4 person.language(); 5 person.speak(); 6 } 7 }
Reproduced in: https: //www.cnblogs.com/wym789/p/6386187.html
https://blog.csdn.net/weixin_41152613/article/details/80894800
Interface is a set of constant values and methods defined. The interface is a special abstract class.
ava is a single-class inheritance.
java interfaces can inherit multiple interfaces.
Class does not allow multiple inheritance The main reason is that if A and B inherits C, b and c and D at the same time there is a method, how to determine the inheritance A one do that?
But the interface does not exist such problems, all interfaces are abstract methods inherited anyone indifferent, so the interface can inherit multiple interfaces.
When the interface inherits multiple interfaces, even if multiple interfaces with the same method, but the final implementation of the interface class can only achieve a method and a method @Override, so call it
There will be no problem
A plurality of interfaces can not inherit a class in java, but may be implemented by a plurality of interface inheritance interfaces. Specific code as follows:
1 public interface LanguageBeharvior { 2 public void language(); 3 }
1 public interface SpeakBeharvior { 2 public void speak(); 3 }
1 public interface PersonBeharvior extends LanguageBeharvior,SpeakBeharvior{ 2 3 }
1 public class Person implements PersonBeharvior{ 2 3 @Override 4 public void language() { 5 6 System.out.println("汉语"); 7 } 8 9 @Override 10 public void speak() { 11 12 System.out.println("人会说话"); 13 } 14 15 }
1 public class Main { 2 public static void main(String[] args) { 3 Person person = new Person(); 4 person.language(); 5 person.speak(); 6 } 7 }