JAVA中什么是封装类,如何使用?

如题所述

java中的封装类是基本类型的封装成对象。
使用方法:
package wrapper;

public class IntegerTest1 {
public static void main(String[] args)
{
Integer i=new Integer(123);
byte b=i.byteValue();
double d=i.doubleValue();
System.out.println("将Integer封装类转换为 byte值为:"+b);
System.out.println("将Integer封装类转换为 double值为:"+d);
String s1=Integer.toBinaryString(i);
String s2=Integer.toOctalString(i);
String s3=Integer.toHexString(i);
System.out.println("转换为二进制的值为:"+s1);
System.out.println("转换为八进制的值为:"+s2);
System.out.println("转换为十六进制的值为:"+s3);
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答