analysis
package com.oop.Demo03;
public class Pet {
public String name;
public int age;
//加public 是给权限
public void shout(){
System.out.println("叫了一声");
}
/*
public class Application {
public static void main(String[] args) {
//引用变量名
Pet dog = new Pet();
dog.name = "xiaohua";
dog.age = 3;
dog.shout();
//引用变量名
Pet cat = new Pet();
cat.name = "xiaomao";
cat.age = 2;
cat.shout();
}
}
*/
}
String is all of the final in the constant pool
All objects that are different each time are in different memory addresses, so they are not the same.
The method area also belongs to the heap, which is a special area. The stack generally contains methods and some references.
Stored in the address, so his mother is not the same
The method area also belongs to the heap, which is a special area. The stack generally contains methods and some references.