Java中八种基本数据类型和八种封装数据类型
初使值的求解过程及比较
作者:Zealjiang
1.八种基本数据类型
创建名为MemberTestBasic的java文件,其内容如下:public class MemberTestBasic
{
/**
八种基本类型
int, short, float ,double, long, boolean, byte, char
*/
int i;
short s;
float f;
double d;
long l;
boolean bo;
byte by;
char c;
public static void main(String[] args)
{
//创建对象m
MemberTestBasic m=new MemberTestBasic();
m.printMember();
}
//为对象m创建一个printMember方法
public void printMember()
{
System.out.print("int->"+i+"\n");
System.out.print("short->"+s+"\n");
System.out.print("float->"+f+"\n");
System.out.print("double->"+d+"\n");
System.out.print("long->"+l+"\n");
System.out.print("boolean->"+bo+"\n");
System.out.print("byte->"+by+"\n");
System.out.print("char->"+c+"\n");
}
}
运行结果如下:
2.八种封装数据类型
创建名为MemberTestEncapsulation的java文件,其内容如下:public class MemberTestEncapsulation
{
/**
八种封装类型
Boolean, Byte, Integer ,Long ,Short ,Float, Double, Character
*/
Integer i;
Short s;
Float f;
Double d;
Long l;
Boolean bo;
Byte by;
Character c;
public static void main(String[] args)
{
//创建对象m
MemberTestEncapsulation m=new MemberTestEncapsulation();
m.printMember();
}
//为对象m创建一个printMember方法
public void printMember()
{
System.out.print("Integer->"+i+"\n");
System.out.print("Short->"+s+"\n");
System.out.print("Float->"+f+"\n");
System.out.print("Double->"+d+"\n");
System.out.print("Long->"+l+"\n");
System.out.print("Boolean->"+bo+"\n");
System.out.print("Byte->"+by+"\n");
System.out.print("Character->"+c+"\n");
}
}。