The difference between the inheritance and interface there are many explanations, I believe that there are a few preliminary understanding of the time some confusion, here published a personal understanding of the explanation, if you can understand it better, you are already a big God, please ignore this understanding incomplete explanation!
First, take a look at his two concepts, and then explain them with the familiar words of saliva.
[extends: Inheriting class]. We define a class in which there is a method body (which is the implementation of some functions), and in another class there is a need for the function in the class we defined earlier, then we can use the extends keyword to inherit the function of the former class. We can refer to the preceding class as the parent class, and the later class is called a subclass, like a son inheriting something from his father, such as property. Represents the extends parent class for subclasses.
Build a class a{//member variable where num is an argument int num=0;//member method, where I is the type parameter public A (int i) {//input int file output below System.out.println (" Aaaaaaaaaaaaaaaaaaa "); System.out.println ("i=" +i);//Assign the input I to the member variable Numnum=i;}} b Inherits AClass B extends A{int num=0;//member method B.public B () {//Inherits the method of Class A. Since B inherits a, it inevitably inherits the characteristics of a. So the input int value 10 is implemented by the method. Super (10); System.out.println ("bbbbbbbbbbbbbbbbbbbb");//The num here is Class B's. System.out.println ("num=" +num);// If you want to display num for Class A, you need to use the following super.num. Note here that NUM needs to be a member variable in Class A. System.out.println ("super.num=" +super.num);}} Build test class Cpublic class C{//mainpublic static void Main (String aa[]) {//new an Object B () new B ();}}
[Implements: Generally means implementation interface]. The keyword used by a class to implement an interface class. Object implements object such as the interface defined in Java Animal, the class that implements the interface is defined as follows: public class Tiger implements Animal
{}
Differences between extends and implements in Java