您的位置:首页 > 编程语言 > Java开发

Java重载Constructor的相互引用(keyword:this)

2008-03-04 20:28 316 查看



class Person...{


String name;


String hobby;


String wife;


int age;






public Person(String name)...{


this.name = name;


}






public Person(String hobby,String wife)...{


this.hobby = hobby;


this.wife = wife;


}






public Person(int age)...{


//this("张无忌");


this("乾坤大挪移","赵敏");


this.age = age;


}






void shout()...{


System.out.println("Name is " + name);


System.out.println("Hobby is " + hobby);


System.out.println("Wife is " + wife);


System.out.println("Age is " + age);


}






public static void main(String[] args)...{


new Person(26).shout();


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐