java类的继承

public class jiaodashu
{
public static void main(String[] args)
{
Teacher t = new Teacher();
//Student s = new Student();
t.setName("小李");
t.setAge(30);
System.out.print(t.getName()+","+ t.getAge());
t.teach();
}
}
public class Penson
{
public String name;
public int age;

public Penson()
{
	System.out.println("无参构造方法");
}

public Penson(String name,int age)
{
	System.out.println("带参构造方法");
	this.name=name;
	this.age=age;
}

public void setName(String name)
{
	this.name = name;
}
public void setAge(int age)
{
	this.age = age;
}
public String getName()
{
	return name;
}
public int getAge()
{
	return age;
}

}
public class Teacher extends Penson
{
public void teach()
{
System.out.println("老师教书");
}
}

public class Student extends Penson
{
public void study()
{
System.out.println("学生学习");
}
}

posted @ 2020-04-23 09:04  田玉斌  阅读(134)  评论(0编辑  收藏  举报