public class Person
{
String name;
int age;
String sex;
public String showName()
{
return name;
}
public void setName(String theName)
{
name = theName;
}
public int getAge()
{
return age;
}
public void setAge(int theAge)
{
age = theAge;
}
public String getSex()
{
return sex;
}
public void setSex(String theSex)
{
sex = theSex;
}
}
{
//扩充父类属性
private String department;
//扩充父类方法
public void setDepartment(String theDept)
{
department = theDept;
}
public String getDepartment()
{
return department;
}
//方法重写
public String showName()
{
return name+"老师";
}
//测试
public static void main(String[] args)
{
Teacher t = new Teacher();
t.setName("Alex");
System.out.println(t.showName());
}
}
public String getName() {
return name;
}
public String getName(String title) {
return name + title;
}
}