数据封装类有什么用,比普通数据类型有什么优势

数据封装类
下面列出了一些数据封装类。引入数据封装类有什么用呢?既然它们是类,就有方法,就可以被我们利用。比如,Integer中toHexString方法,可以轻松吧十进制转换成16进制数,马克-to-win:而你int简单类型有这功能吗?
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



Boolean boolean
Character char
Double double
Float float
Integer int
Long long
Short short
Byte byte
Void void

3.Math 类
用来完成一些常用的数学运算。




例2.2.1---本章源码

public class Test {
    public static void main(String[] args) {
        Integer in = new Integer(5);
        Integer in1 = new Integer("67");
        Boolean b = new Boolean(true);
        System.out.println("Mark 16进制是 "+Integer.toHexString(17));
        System.out.println(in.intValue());
        System.out.println(in1.intValue());
        System.out.println(b.booleanValue());
        System.out.println("马克-to-win Bigger number is " + Math.max(4, 5));
    }
}

 

result is:

Mark 16进制是 11
5
67
true
马克-to-win Bigger number is 5


Assignement:

1) make three classes cat,dog,animal, what is the relationship among them?

2) make three classes jeep, bicycle, vehicle,, what is the relationship among them?

3)make three classes figure,triangle,rectangle, what is the relationship among them?