Understanding of JAVA classes and objects

1: Classes and objects can be simply understood as some things in life, such as cars, and objects can be understood as every car on the production line. Classes describe the properties and behavior of objects, and classes can also be said It is a drawing or template of an object. An object is an instance of a class. A class can correspond to multiple objects. Different cars are produced corresponding to multiple objects.

Java中通过关键字class定义“类”,后跟类名。例如:
class Car{
    
    
  // 类的主体内容
}

2: When defining a class, two types of elements can be set in the class: data members and member functions. The data member is an object, which can be of any type. If it is a handle to an object, this handle must be initialized and connected to an actual object through the constructor.

class Car{
    
    
  String name;
  double salary;
}

3: You can create an object through the new keyword. Such as:

Car c = new Car();

3: The default value of the main member, a certain main data type belongs to a class member, then even if it is not explicitly initialized, it can be guaranteed that they get a default value.
Insert picture description here

4: The relationship between classes
(1) Dependence: The methods of one class manipulate the objects of another class.
(2) Aggregation: An object of one class contains objects of another class.
(3) Inheritance: Used to express the relationship between special and general. If class A extends class B (A inherits B), class A not only contains methods of class B, but also extends methods.

5: Object characteristics
(1) Objects have attributes and behaviors.
(2) The object has a changing state.
(3) The object is unique.
(4) Objects are all instances of a certain category.
(5) Everything is an object, and everything in the real world can be regarded as an object.

6: The object also has three characteristics that are more convenient for development
(1) Reusability: code reuse, reduce the amount of code, and improve development efficiency. The three core object-oriented features (inheritance, encapsulation, and polymorphism) described below are all around this core.
(2) Scalability: New functions can be easily added to the system to facilitate software modification.
(3) Manageability: It can combine functions and data to facilitate management.

Guess you like

Origin blog.csdn.net/weixin_44941105/article/details/115149597