The interface can inherit multiple interfaces summary

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. 

 Interface extends the interface is essentially an abstract class inherits from another abstract class (they did not write an instance method). When a class inherits an abstract class, it must override the parent class
Abstract method of the abstract class, if they do not override the parent class instance of the abstract method, then this class is an abstract class (abstract subclass until overwritten until the abstract method of this example,
To get rid of abstract fate).

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 }
LanguageBeharvior
1 public interface SpeakBeharvior {
2     public void speak();
3 }
SpeakBeharvior
1 public interface PersonBeharvior  extends LanguageBeharvior,SpeakBeharvior{
2  
3 }
PersonBeharvior
 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 }
Person
1 public class Main {
2        public static void main(String[] args) {
3            Person person = new Person();
4             person.language();
5             person.speak();
6     }
7 }
Main

 

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. 

 Interface extends the interface is essentially an abstract class inherits from another abstract class (they did not write an instance method). When a class inherits an abstract class, it must override the parent class
Abstract method of the abstract class, if they do not override the parent class instance of the abstract method, then this class is an abstract class (abstract subclass until overwritten until the abstract method of this example,
To get rid of abstract fate).

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 }
LanguageBeharvior
1 public interface SpeakBeharvior {
2     public void speak();
3 }
SpeakBeharvior
1 public interface PersonBeharvior  extends LanguageBeharvior,SpeakBeharvior{
2  
3 }
PersonBeharvior
 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 }
Person
1 public class Main {
2        public static void main(String[] args) {
3            Person person = new Person();
4             person.language();
5             person.speak();
6     }
7 }
Main

 

Guess you like

Origin www.cnblogs.com/zt007/p/11578418.html