-
1.Abstract Classes: Specifies a set of methods and methods that must be implemented by the inheritance class.
Abstract classes cannot be instantiated due to the existence of abstract methods. You can think of abstract classes as rough houses, doors, windows, and walls, and the style is determined by yourself, so the difference between abstract classes and ordinary classes as base classes is that they are more restrictive.
2.Interface Class: Much like an abstract class, the method defined in the interface must be implemented by the reference class, but the fundamental difference between it and the abstract class is the purpose:
The rules of communication with different individuals, you need to have a key to enter the dormitory, this key is the interface between you and the dormitory, and your roommate also has this interface, so he can also enter the dormitory, and you use your mobile phone to talk, then the mobile phone is the interface for you to communicate with others.
3.Differences and associations:
1.An interface is a variant of an abstract class, all methods in an interface are abstract, and there can be non-abstract methods in an abstract class, and an abstract class is a class that declares the existence of a method without implementing it.
2.Interfaces can be inherited, abstract classes cannot.
3.The interface defines the method, there is no implementation, while the abstract class can implement part of the method 4The basic data type in the interface is static, while the abstract class is not.
-
1. The interface can be inherited multiple times, but the abstract class cannot.
2. The interface definition method is not implemented; The abstract class can implement some of the data members of the basic data types in method 3 and the interface, which are static and final by default, but the abstract class is not.
If you know in advance that something is going to be the base class, the first option is to turn it into an interface.
Abstract classes should only be considered if they must be defined using methods or member variables.
-
The differences between abstract classes and interfaces are as follows:1. The common method provides the method body.
The interface can only contain abstract methods, static methods and default methods, and cannot provide method implementations for ordinary methods, while abstract classes can contain ordinary methods, and ordinary methods in the interface are abstract methods by default.
2. PublicStaticFinal.
The member variables in the abstract class can be of various types, while the member variables in the interface can only be of the publicstaticfinal type, and must be assigned, otherwise the compilation will not pass.
3. a constructor.
The interface is unbalanced and coarse can contain constructors, and abstract classes can contain constructors, and the constructors in abstract classes are not used to create objects, but are called by their subclasses to complete the initialization of abstract classes.
4. Initialize the block.
An interface cannot contain an initialization block, but an abstract class can contain an initialization block.
5. Inherit an abstract class and multiple interfaces.
A class can inherit only one abstract class, whereas a class can implement multiple interfaces.
-
The difference between "abstract class" and "interface":
1. Interfaces can be multi-implement*, and abstract classes can only be single-extended.
2. The interface is only defined, and the abstract class can be defined and implemented.
3. The default field definition of the interface is: public static final, and the default of abstract field is "friendly".
4. There is no constructor for the interface, and the abstract class can have a constructor.
Abstract classes. Abstract classes are used to capture the common characteristics of subclasses. It cannot be instantiated, it can only be used as a superclass of subclasses. Abstract classes are templates that are used to create subclasses in the inheritance hierarchy.
Interface. An interface is a collection of abstract methods. If a class implements an interface, it inherits the abstraction of that interface.
It's like a contract pattern, and if you implement this interface, you have to make sure that you use these methods. The interface is just a formality, and the interface itself cannot do anything.
-
1. Neither abstract classes nor interfaces can be instantiated directly. If you want to instantiate, the abstract class variable must point to a subclass object that implements all abstract methods, and the interface variable must point to a class object that implements all interface methods.
2. Abstract classes should be inherited by subclasses, and interfaces should be implemented by classes.
3. The interface can only be used for method declaration, and method declaration can be made in the abstract class, and method implementation can also be done.
4. The variables defined in the interface can only be public static constants, and the variables in the abstract class are ordinary variables.
5. The abstract methods in the abstract class must all be implemented by the subclass, if the subclass cannot fully implement the abstract methods of the parent class, then the subclass can only be an abstract class. Similarly, if you can't implement all of the interface methods, then the class can only be an abstract class.
6. Abstract methods can only be stated, not realized.
An interface is an abstraction (which can be another entity) that an entity provides to the outside world to separate the external communication method from the internal operation, so that it can be modified internally without affecting the way other entities interact with it in the outside world.
Abstract classes are often used to represent abstract concepts derived from the analysis and design of problem domains, which are abstractions of a series of concrete concepts that look different but are essentially the same.
Interfaces are reference-typed, and there are three similarities to abstract classes:
1. It cannot be instantiated.
2. Include unimplemented method declarations.
3. The derived class must implement the unimplemented method, the abstract class is the abstract method, and the interface is all the members (not only the method but also other members).
-
Answer according to three points: first answer attributes: abstract classes can have ordinary member variables, but interfaces can't;
Then answer the method: the abstract class has a non-abstract method and a constructor, and the modifier can be private, the interface can only be an abstract method, and the modifier is public, and finally it can only inherit one abstract class, but can implement multiple interfaces.
Members of abstract classes can have access levels, while members of interfaces are all public levels. >>>More
After the move, your general (commander) is not attacked (including the commander in person), it is a legal step. >>>More
DVI is better than VGA and technically more advanced than VGA. >>>More
Solution: (1) Because f(x y) = f(x)-f(y)(x,y>0).
Therefore, if x=y 0, then there is f(1)=f(x)-f(x)=0i.e. f(1)=0.(2). >>>More
A hard wire is a control circuit consisting of wires, contacts, switches, etc., and should not include logic devices.