黑马程序员技术交流社区

标题: 求指点 char 类型输出问题. [打印本页]

作者: 夏季熬成了秋    时间: 2014-6-5 19:32
标题: 求指点 char 类型输出问题.
本帖最后由 夏季熬成了秋 于 2014-6-6 20:54 编辑
  1. class StudentTest{
  2.         public static void main(String [] args){
  3.                 Student s1 = new Student();
  4.                 s1.show();
  5.         }
  6. }
  7. class Student {
  8.         private String name;
  9.         private int age;
  10.         private char sex;
  11.         //无参构造;
  12.         Student(){        
  13.         }
  14.         //整型构造;
  15.         Student(int a){        
  16.         }
  17.         //字符串构造;
  18.         Student(String s){
  19.         }
  20.         //字符构造;
  21.         Student(char c){
  22.         }
  23.         
  24.         
  25.         //name 的输入输出判定;
  26.         public void setName(String name ){
  27.                 this.name = name;
  28.         }
  29.         public String getName(){
  30.                 return name;
  31.         }
  32.         
  33.         
  34.         //age 的输入输出判定;
  35.         public void setAge (int age){
  36.                 this.age = age;
  37.         }
  38.         public int getAge (){
  39.                 return age;
  40.         }
  41.         
  42.         
  43.         //sex 的输入输出判定;
  44.         public void setSex (char sex){
  45.                 this.sex = sex;
  46.         }
  47.         public char getSex (){
  48.                 return sex;
  49.         }
  50.         
  51.         
  52.         //输出Student的所有属性.
  53.         public void show (){
  54.                 System.out.println("Name = "+ name +"\n"+ "Sex = " + sex + "\n" + "Age = " + age);
  55.         }
  56. }
复制代码


输出结果  :
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