int与Integer的不同点

int与Integer的不同点?

(1)int类基本数据类型,而Integer为引用数据类型

(2)int占4个字节,用于存储int类型的值,  Integer占4个字节,用于存储Integer对象的内存地址

(3)作为成员变量时,int的默认值为0,Integer的默认为null

(4)Integer使用null表示没有创建Integer对象,使用0代表已创建对象,值为0

Integer i=0;

Integer i=null;

private   int   age;   在写类的属性时,建议使用基本数据类型,因为只存"值"即可。

【2】String类

  String类中常量,其值一旦创建不能更改,只能被共享

 String str="abc";

  str="bcd";

猜你喜欢

转载自blog.csdn.net/wyqwilliam/article/details/92803137