The difference between abstract classes and interfaces
1. In common
Can contain abstract methods;
2. The difference between
- An abstract class is a “class” that is used
class
Declared as a keyword; An interface is another kind of data that is usedinterface
Declared as a keyword; - Abstract classes can have various properties with different permissions and modifiers, and can contain ordinary methods, abstract methods, or no ordinary methods at all, or no abstract methods at all. All members of the interface are
public
Of, all of the properties arestatic
,final
Before JDK 1.8, all methods were abstract; - The relationship between a common class and an abstract class is “inheritance”. When a common class inherits an abstract class, it has the obligation to rewrite the abstract method in the abstract class. In Java statements, the inheritance between classes is 1 to 1. The relationship between a common class and an interface is “implementation”. When a common class implements an interface, it is also obliged to rewrite all abstract methods in the interface. The implementation relationship between a class and an interface is 1-to-many, that is, a class can simultaneously implement several interfaces. Interfaces can also inherit from one another in a one-to-many relationship. That is, one interface can inherit from several interfaces at the same time.
3. Use experience/installation
Classes describe categories; Interface, is to describe the shape of patterns, behavior characteristics, norms, standards!
The relation between classes is A; The relationship between a class and an interface is has A.
public class Person { public String name; }
public class Student extends Person {}
public class Teacher extends Person {}
public class Animal {}public class Cat extends Animal {}
public interfacelearning{ voidTo learn (a parameter); }public interfaceteaching{}
public interfacedriving{ voidDriving (a parameter); }public class Person implementsStudy, teach, drive{} Person =newPerson(); The Person li si =new Person();
Copy the code
Attachment 1: Eclipse common shortcuts
Ctrl + Shift + F | Formatting code (code layout) |
---|---|
Ctrl + Shift + O | finishingimport Statements (add necessary, remove unnecessary) |
Alt + up/down | To move a single line of code, place the cursor on that line before operating. Move several lines of code, need to be checked before operation |
Ctrl + Alt + Direction up/Direction down | Copy several lines of code up/down in the same manner as moving the entire line |
Alt + Shift + R | To rename a variable or method in the current source file, select the entire name before performing the operation |
Ctrl + D | Deletes entire lines or lines of code in the same manner as moving entire lines of code |
To be continued…