Chapter 3 Knowledge Points

 How to create objects, call properties and methods in Java.
(1) Create an object through the construction method, such as "Penguin p=new Penguin( ):.
(2) Call the attribute through the object name. The attribute name, such as "p.name="qq" 
(3) Through the object name .The method is called by the method name, such as "p.print( );

if the same class contains two or more methods, their method names are the same, the number of method parameters or parameter types are different, then it is called The method is overloaded. This process is called method overloading. Both member methods and constructor methods can be overloaded.

The judgment of method overloading is based on the following.

(1) Must be in the same class.
(2) The method name is the same (3) The
parameter list (the number of method
        parameters or the parameter type) is different.
(4) It has nothing to do with the method return value and method modifier.

(5) When using this to call other constructors of itself, It can only be used as the first statement.


Usage of static
(1) In the process of loading a class, the memory allocation of static variables is completed, and then the static block is executed,
both of which are executed before
the .
(2) Class attributes and Class methods can be accessed by class name and object name, instance properties and instance methods can only be accessed by object name, and
class methods can only be accessed by class properties and other class methods.



Specific steps of encapsulation: Modify the visibility of properties to restrict access to properties: create a pair of setter and getter methods for each property for access to these properties; in the assignment method , adding an access control statement to the property.


The benefits of encapsulation: hide the implementation details of the class; allow users to access data only through the methods specified by the program; can easily add access control statements to limit unreasonable operations.


When encapsulating, multiple permission controllers are used to modify member variables and methods. The differences are as follows.


(1) private: Member variables and methods can only be accessed in the class in which they are defined, with class visibility.
(2) Default: Member variables and methods can only be accessed by classes in the same package, with package visibility.
  
(3) protected: can be accessed by classes in the same package and by subclasses in different packages in the same project.


This chapter concludes:
(1) The real world is "object-oriented", and object-oriented is to use the method of "reality simulation" to design and develop programs.
(2) Object-oriented design is currently the most popular technology in computer software development. The process of object-oriented design is the process of abstraction.
(3) A class is a description of a certain class of things, an abstract and conceptual definition. The object is that the individual of the thing that actually exists is concrete and actual.
(4) If the same class contains two or more methods, their method names are the same, and the number of method parameters or parameter
types are different, the method is said to be overloaded, and this process is called method overloading. .
(5) Constructors are used to create objects of a class. The main function of the constructor is to perform some initialization operations when creating an object. Various initialization behaviors can be implemented through constructor overloading.
(6) Encapsulation is to declare the member properties of a class as private, and provide public methods to access the member properties
operate.
(7) Benefits of encapsulation: Hide the implementation details of the class: allow users to access data only through the methods specified by the program; access control statements can
be easily added to limit unreasonable operations.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325957062&siteId=291194637