The object-oriented feature is that programmers can design required classes based on specific problems to solve problems. It has features such as encapsulation, inheritance, and polymorphism, including object-oriented analysis, object-oriented design, and object-oriented programming.
1> encapsulation is to combine object attributes and methods to provide unified access permissions. Encapsulation can separate the user and design of the program. The designer designs the content that can be used for external operations and internal operations. The user only uses the content of the designed external operations. Encapsulation can effectively protect data and method operations in programs.
Modifier public: attributes and Methods Modified by public. Any other class can be accessed freely,
PRIVATE: attributes and Methods Modified with private. Except for the current class, other classes cannot be directly accessed,
Protect: the attributes and Methods Modified by protect allow access by other classes or subclasses of different packages in the same package,
The attributes and methods of the default modifier allow access by other classes in the same package, and do not allow access by classes (including subclasses) in other packages.
2> used for inheritance, implemented by the extends keyword. The subclass inherits all attributes and methods of the parent class except the constructor. The super keyword is used to call the constructor of the parent class. When super is used to call the constructor of the parent class, it should be written before the subclass constructor. The permission in the subclass method cannot be weaker than the permission in the access parent Method
The Java. Lang. object class is the parent class of all classes. When a class does not use extends to display the inheritance relationship, this class inherits the object class by default.
In Java, only single inheritance is allowed, and multiple inheritance is not allowed. That is, if a inherits B, it cannot inherit other classes.
Java has multi-layer inheritance, that is, a can inherit B, B can inherit C, C can inherit other classes, including indirect inheritance
3> polymorphism is to assign the subclass object to the parent class. When the parent class is referenced to call a method, the specific execution method is the subclass object.
4> An internal class refers to another class defined within a class. Internal classes can make the code block compact and improve modularity.
Internal classes can access external class variables, while external class functions cannot access variables in internal class functions.
5> the constructor is the same as the class name, and no return type (including void) is added before it ). The constructor can be used to conveniently initialize objects. If you customize a constructor, the compiler will no longer automatically generate a constructor without parameters. Therefore, an empty constructor should be defined before class objects are generated in the main function.
In the constructor, only one of this and super can appear, and this and super should appear as the first sentence.
6> there are two methods for object comparison: "=" and "equals". The former is used to compare whether the values of variables are equal,
The latter is used to compare whether the content of two objects is equal. The usage is as follows:
A = B a. Equals (B)
7> the internal class defined in the method can only access local variables of the final type in the method. The local variable defined by fianl is equivalent to a constant, and its life cycle exceeds
Lifecycle
8> variables defined by final are considered constants, assign values to variables defined by final or assign values to variables defined by final in the following Constructor (if the final variables are assigned values in the constructor, you need to do the same for other constructor methods in this class)
9> abstract class. If a class has one (or more) abstract method, the class is an abstract class.
Abstract classes can define non-abstract methods.
Abstract classes cannot generate any instance objects, that is, they cannot be generated using the new keyword.
The subclass of an abstract class must overwrite all abstract methods before it can be instantiated. Otherwise, this word class is still an abstract class.
10> interface. If all methods in an abstract class are abstract, this class can be defined as an interface. Java does not allow multiple inheritance. To implement the functions of multiple classes, you can implement multiple interfaces.
A class can inherit a parent class and implement one or more interfaces. The extends keyword must be before the implements keyword.
11> comparison between abstract classes and interfaces: 1) abstract class represents an inheritance relationship in Java. A class can only use one inheritance link at a time, but one class can implement multiple interfaces.
2) an abstract class can contain its own data members, non-abstract member methods, and abstract methods. In the interface, there can only be static data members that cannot be modified (that is, static final), and all member methods are public abstract.
3) classes that implement abstract classes and interfaces must implement all the abstract methods. Abstract classes can have non-abstract method implementations, while interfaces cannot have method implementations.
4) In general, when using inheritance, you should first consider defining interfaces.
5) when an interface is implemented, all methods in the interface must be implemented. If some methods are implemented, they should be defined as abstract classes.
12> throws exception should be used in advance to remind programmers of functions that may be faulty.
13> no one is in touch with the parent package and the Child package. To use the class in the parent package, write the detailed package name, and vice versa.
After the package name is declared using the Import Statement, the following call can save the package name to be called
14> the compiler reports that the class cannot be found, which can be analyzed from three aspects: 1) Case sensitivity of the Class Name
2) whether the package name is correct or 'import'
3) whether the path is set correctly