1 public class TEST { 2 3 public static void main(String[] args) { 4 Teacher t1=new Teacher(50,"刘三","教师"); 5 Worker t2=new Worker(30,"赵四","工人"); 6 t1.talk(); 7 t2.talk(); 8 9 } 10 11 } 12 abstract class Person{ 13 private String name; 14 private int age; 15 16 public Person(int age,String name){ 17 this.age=age; 18 this.name=name; 19 } 20 public String getname() { 21 return name; 22 } 23 public int getage() { 24 return age; 25 } 26 } 27 class Teacher extends Person{ 28 String job="教师"; 29 public Teacher(int age,String name,String job){ 30 super(age,name); 31 this.job=job; 32 } 33 public void talk() { 34 System.out.println("教师->姓名:"+getname()+",年龄,"+getage()+"职业:"+job); 35 } 36 } 37 class Worker extends Person{ 38 String job="工人"; 39 public Worker(int age,String name,String job){ 40 super(age,name); 41 this.job=job; 42 } 43 public void talk() { 44 System.out.println("工人->姓名:"+getname()+",年龄,"+getage()+"职业:"+job); 45 } 46 }