目标
认识包装类
用过的类
int,基本类型
Integer,引用类型(对象类型,包装类)
自定义包装类
public class SuperInt {
// 数据
public int num;
// 实例化时传一个参数
public SuperInt(int i) {
this.num = i;
}
public SuperInt() {
}
public int sanBei() {
return this.num * 3;
}
public int erBei() {
return this.num * 2;
}
@Override
public String toString() {
return "" + this.num;
}
}
测试自定义包装类
public class Test {
public static void main(String[] args) {
// 实例化自定义的超级整数类
SuperInt superInt = new SuperInt(6);
// 翻倍方法
int erBei = superInt.erBei();
System.out.println(erBei);
// 三倍方法
int sanBei = superInt.sanBei();
System.out.println(sanBei);
// int Integer boolean Boolean
}
}
运行效果
12
18