?? person4.java
字號:
public class Person4
{
static int count=0;
protected String name;
protected int age;
public Person4(String n1,int a1) //構造方法
{
this.name = n1;
this.age = a1;
this.count++;
}
public int olderthen(Person4 b) //比較兩個人的年齡
{
Person4 a = this; //指代對象本身
return a.age - b.age;
}
public void print()
{
System.out.print(this.getClass().getName()+" ");
System.out.print("count="+this.count+" ");
System.out.println(" "+this.name+", "+this.age);
}
}
class Student4 extends Person4
{
protected String dept;
Student4(String n1,int a1,String d1) //不能繼承超類的構造方法
{
super(n1,a1); //調用超類的構造方法
dept = d1;
}
public static void main(String args[])
{
Person4 p1 = new Person4("李大廣",21);
p1.print();
Student4 s1 = new Student4("陳小瑞",19,"計算機系") ;
s1.print();
System.out.println("年齡差= "+p1.olderthen(s1));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -