Java classes and objects

insert image description here



The simplest class, an empty shell, class A{}without any properties and methods
Objects, A object1 = new A(); A object2 = new A();these are two objects, both of which are of type A, but they are two different objects with different storage addresses in memory, there are no two objects are exactly the same

A class is a definition, a specification is a dead thing
An object is an instance, an implementation of a class, a concrete thing

Example:
Human -----" A handsome little XXX like me


A object = new A();object is equivalent to a pointer, object assignment is pointer assignment, memory address, basic type is direct value copy

public class Demo07 {
    
    
    public static void main(String[] args) {
    
    
        int num1 = 2;
        int num2 = num1;
        System.out.println("num1:"+num1+",num2:"+num2);
        num2 = 10;
        System.out.println("num1:"+num1+",num2:"+num2);
    }
}

A class is a specification, an abstraction, an object actually exists, and it actually exists in memory. The basic variable assignment value is copied, and the object assignment points to the same pointer. If there is no initialization in the class member, there is a default value. If the function temporary variable is not initialized, it is There is no default value, so it must be initialized


insert image description here

Guess you like

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