Question 1 interfaces can inherit interfaces. Question 2 abstract classes can implement interfaces. Question 3: An abstract class can inherit a specific class, provided that the object class must have a clear constructor. Proof: All classes are inherited from the object class.
The following explains the meaning of "entity classes must have clear constructors:
-1. If the constructor is not written, the constructor has no public constructor by default. The sub-class can do nothing and let the default constructor call it. This is the first two lines of code.
-2. Write the non-argument constructor that can be accessed by sub-classes. The sub-classes can be called by default instead of writing anything.
-3. if the parameter constructor is written but the parameter constructor is not written, there is no sub-class accessless parameter constructor in the parent class. The sub-class must be written in the first sentence of the sub-class constructor, call the parameter constructor of the parent class and pass the parameter in.
-4. Classes declared as final and all constructors that are not within the subclass access permission cannot be inherited.
In fact, as long as the class is inherited, no matter the abstraction or entity, it must comply with this rule. In this inheritance experiment, the results remain unchanged if the prefix of abstract is deleted or added at any time. I personally think that the phrase "entity classes must have clear constructor" cannot clearly express this situation, so the majority of job seekers can still write clearly.
My favorite syntax is "yes, but like the inheritance of object classes, it also requires that the parent class can be inherited and has a constructor that can be accessed by sub-classes ."
Question 4: The abstract class can contain static main methods.
Keep in mind that the only difference between an abstract class and a common class is that you cannot create an instance object or allow the Except CT method!
I think ---- the member variables in the abstract class can only be normal member variables or public static final. The member methods in the abstract class can only be normal member methods or public abstract!
Question 5: What is the difference between abstractclass and interface?
The class containing the abstract modifier is an abstract class, and the abstract class cannot create instance objects. Classes that contain abstract methods must be defined as abstract class. Methods in abstract class do not need to be abstract. Abstract methods defined in the abstract class must be implemented in the concrete subclass. Therefore, there cannot be abstract constructor or abstract static methods. If the subclass does not implement all abstract methods in the abstract parent class, the subclass must also be defined as abstract.
An interface can be said to be a special case of an abstract class. All methods in an interface must be abstract. The method definition in the interface defaults to public abstract, and the member variable type in the interface defaults to public static final.
The following compares the syntax differences between the two:
1. abstract classes can have Constructor (non-Abstract) and interfaces cannot have constructor.
2. abstract classes can contain common member variables. The interface does not contain common member variables.
3. abstract classes can contain non-Abstract Common methods. All methods in the interface must be abstract and cannot have non-Abstract Common methods.
4. abstract classes can access public, protected, and (default type, although there is no error in eclipse, but it should not), but the abstract methods in the interface can only be public, the default value is public abstract.
5. abstract classes can contain static methods (non-Abstract), and interfaces cannot contain static methods.
6. the abstract class and interface can contain static member variables. The access type of static member variables in the abstract class can be any, but the variables defined in the interface can only be of the public static final type, the default value is public static final.
7. A class can implement multiple interfaces, but can inherit only one abstract class.
Differences between the two in application: interfaces mainly play a role in the system architecture design method and are used to define the communication contract between modules. abstract classes play a role in code implementation methods and can realize code reuse, for example, the template method design pattern is a typical application of abstract classes.
Question 6 can the abstract method be static, native, or synchronized at the same time?
The answer is no.
20 interfaces, abstract classes, inheritance