package demo;
class Person2
{
String name;
int age;
public Person2(String na,int ag)
{
name=na;
age=ag;
}
void print()
{
System.out.println("父亲: 姓名:"+name+" 年龄:"+age);
}
}
public class Teacher2 extends Person2{
String department,name;
public Teacher2(String na,int ag,String de,String nal)
{
super(na,ag);
department=de;
name=nal;
}
void setname_p(String na)
{
super.name=na;
}
void setname_s(String na1)
{
name=na1;
}
void print()
{
super.print();
System.out.println("儿子: 姓名:"+name+" 专业:"+department);
}
public static void main(String[] args) {
Teacher2 t;
t=new Teacher2("王大锤",30,"信息系","王小二");
t.print();
System.out.println("-------------------------------");
t.setname_p("王尼玛");
t.setname_s("王麻子");
t.print();
}
}
运行后结果如下: