?? infoperson.java
字號:
class Person {
public String name;
public char sex;
public int age;
//設(shè)置默認(rèn)值
Person(){
name = "wangliangliang";
sex = 'm';
age = 18;
}
//對象作為構(gòu)造函數(shù)的參數(shù)
Person(Person p){
name = p.name;
sex = p.sex;
age =p.age;
}
//指定值初始化對象
Person(String name,char sex,int age){
this.name = name;
this.sex = sex;
this.age = age;
}
//輸出person的基本信息
public void info(){
System.out.println("The Person "+name+" is a "+sex+", aged "+age);
}
}
//類Chinese繼承類Person
class Country extends Person{
public String nation;
//指定值初始化類Chinese的對象
Country(String n,char s,int a,String na){
name = n;
sex = s;
age = a;
nation = na;
}
}
public class InfoPerson{
public static void main(String []args){
Country cou1 = new Country("zhanghua",'m',22,"China");
Country cou2 = new Country("chenyan",'f',21,"China");
System.out.print("The base info of the person is:");
cou1.info();
System.out.println("The nationality of the person is:"+cou1.nation);
System.out.print("The base info of the person is");
cou2.info();
System.out.println("The nationality of the person is:"+cou2.nation);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -