Student实体类里面有int、String等变量,创建1000个该对象程序运行所占用内存肯定也变大。如果在该类里面声明一个方法,内存是否也会随着对象创建数目变大而变大(抛开变量的因素)?如果将该方法声明为static呢?
public class Student {
public String name;
public int age;
public String address;
public int level;
public String remark;
public String getMsg() {
if (age > 0) {
if (level > 0) {
return "abc" + address;
} else {
return "bcd" + remark;
}
} else {
if (level > 0) {
return "we" + remark;
} else {
return "ewt" + address;
}
}
}
}