1. Object-oriented three major features inheritance, encapsulation, polymorphism what is inheritance? ① inheritance is one of the important reasons that object-oriented programming can improve the efficiency of software development. ② inheritance is transitive, just as the grandson of reality not only looks like his father but also his grandfather. The properties and methods inherited by ③ are implicit, which is invisible in this class. ④ A class can have only one parent class, that is, a class can only be single-inheritance. ⑤ an interface can have more than one parent class, that is, an interface can be multiple inheritance. In the actual project development, one class inherits from another class, then the former is the subclass of the latter, and vice versa. What is encapsulation? The object data and the instructions that manipulate the object are part of the object itself, enabling you to hide the data as externally as possible. In actual project development, the use of the most encapsulated entity classes, often with JavaBean (the class must be concrete and public, and with parameterless constructors) together. So what do the entity classes have? A: Private member variables, parameterless constructors, parameterized constructors, setter and getters methods, overriding the ToString method, overriding Hashcode, and the Equals method. What is polymorphic? ① polymorphism is that objects have many forms: reference polymorphism and Method polymorphism. ② Reference polymorphism: A reference to a parent class can point to an object of this class, a reference to a parent class that can point to a child class. ③ method Polymorphism: When creating this class object, the method called is the method of this class; When you create a subclass object, the method that is called is the method that the subclass overrides or the inherited method. ④ There are conditions for polymorphism: inheritance, rewriting. The role of ⑤ polymorphism is to eliminate the coupling relationship between types. In the actual project development, Class A inherits Class B, if the class B method is not rewritten in Class A, the output is still the information in the class B method (b b=new A ()), and if the class B method is overridden in Class A, the output is the information in the Class A method (b b=new A ()).
Three main features of Java object-oriented