黑马程序员技术交流社区
标题:
求指点 char 类型输出问题.
[打印本页]
作者:
夏季熬成了秋
时间:
2014-6-5 19:32
标题:
求指点 char 类型输出问题.
本帖最后由 夏季熬成了秋 于 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'的吗?
求指点~
作者:
pk49800
时间:
2014-6-5 21:31
输出的应该是空格,‘\u0000’就是空格吧
作者:
夏季熬成了秋
时间:
2014-6-6 20:50
pk49800 发表于 2014-6-5 21:31
输出的应该是空格,‘\u0000’就是空格吧
thank you!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2