數(shù)據(jù)封裝類有什么用,比普通數(shù)據(jù)類型有什么優(yōu)勢

數(shù)據(jù)封裝類
下面列出了一些數(shù)據(jù)封裝類。引入數(shù)據(jù)封裝類有什么用呢?既然它們是類,就有方法,就可以被我們利用。比如,Integer中toHexString方法,可以輕松吧十進(jìn)制轉(zhuǎn)換成16進(jìn)制數(shù),馬克-to-win:而你int簡單類型有這功能嗎?
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號: 73203。



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

3.Math 類
用來完成一些常用的數(shù)學(xué)運(yùn)算。




例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進(jìn)制是 "+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進(jìn)制是 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?