object,包装
object类:
class A{
//此类隐含继承Object类
}
public class Objiekete {
public static void main(String[] args) {
A a=new A();
a.toString();//toString方法继承的是Object类的方法
a.equals(a); //同上
//object是所有类的父类
}
}
包装类:
class X{
private char ch;
public X(){};
public X(char ch){
this.ch=ch;
}
public char getCh(){return this.ch;}
//包装的目的,是为了调用其他普通方法
public char daxie(){//将字符ch转为大写的方法
return (char)(ch-32);
}
}
public class Baozhuanglei {
public static void main(String[] args) {
char ch='r';
X x=new X(ch); //包装类-> 包装到类的对象里面去
char c=x.getCh();//从对象里取出来
System.out.println(c);
System.out.println(x.daxie());
}
}
浙公网安备 33010602011771号