本帖最后由 夏季熬成了秋 于 2014-6-6 20:54 编辑
- class StudentTest{
- public static void main(String [] args){
- Student s1 = new Student();
- s1.show();
- }
- }
- class Student {
- private String name;
- private int age;
- private char sex;
- //无参构造;
- Student(){
- }
- //整型构造;
- Student(int a){
- }
- //字符串构造;
- Student(String s){
- }
- //字符构造;
- Student(char c){
- }
-
-
- //name 的输入输出判定;
- public void setName(String name ){
- this.name = name;
- }
- public String getName(){
- return name;
- }
-
-
- //age 的输入输出判定;
- public void setAge (int age){
- this.age = age;
- }
- public int getAge (){
- return age;
- }
-
-
- //sex 的输入输出判定;
- public void setSex (char sex){
- this.sex = sex;
- }
- public char getSex (){
- return sex;
- }
-
-
- //输出Student的所有属性.
- public void show (){
- System.out.println("Name = "+ name +"\n"+ "Sex = " + sex + "\n" + "Age = " + age);
- }
- }
复制代码
输出结果 :
Name = null
Sex =
Age = 0
问题:为什么会是Sex = 不是应该是 '\u0000'的吗?
求指点~ |