Chapter 1 Knowledge Points

1. Create a class


1. Define the class name


            syntax:


            public class class name {


            }


2. Write the properties


    of the class Describe the static characteristics (properties) of the class by defining variables in the body of the class, these variables are called members of the class variable.


3. Write the methods


    of the class Describe the behavior of the class by defining methods in the class, these methods are called member methods of the class.


    Syntax:


    access modifier return value type method name() {


    // method body


    }


2. Create and use objects


  1. Create object:


    syntax:


    class name object name = new class name ();


 2. Use object:


    syntax:


    object Name.Attribute//The attribute


    object name of the reference object. Method name ()//The method of applying the object


3. The advantages of facing the object:


 1. Consistent with human thinking habits: The object-oriented way of thinking starts from the perspective of human thinking about problems, and transforms the thinking process of human beings to solve problems into a process that can be understood by programs. Object-oriented programming allows us to use "classes" to simulate abstract concepts in the real world, and "objects" to simulate real-world entities, thereby using computers to solve real-world problems.


 2. Information hiding, which improves the maintainability and security of the program: Encapsulation realizes modularization and information hiding, that is, the attributes and behaviors of the class are encapsulated in the class, which ensures that their modifications will not affect other objects, Good for maintenance. At the same time, encapsulation makes it impossible to freely access the properties and methods of the object outside the object, avoids the influence of external errors on it, and improves the security.


 3. Improve the reusability of the program: a class can create a pair of object instances, which increases the reusability.




This chapter summarizes:


 1. An object is an entity used to describe objective things, consisting of a set of properties and methods.


 2. A class defines the characteristics (properties) and behaviors (methods) that an object will have.


 3. The relationship between classes and objects is abstract and concrete. A class is the type of an object, and an object is an instance of a class.


 4. The attributes and methods of the object are encapsulated together in the class, complement each other and are inseparable.


 5. The steps to use a class are as follows:


   1. Define a class: use the keyword class.


   2. Create an object of a class: use the keyword new.


   3. Use the properties and methods of the class: Use the "." operator.



Guess you like

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