//学生跟教师.
abstract class Person
{
//定义私有的成员属性
private String name;
private int age ;
//给个无参的构造方法
public Person(){
}
public Person(String name , int age){
this.name = name;
this.age = age;
}
piublic String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
//成员方法
public void sleep(){
System.out.println("睡觉咯");
}
//重写吃东西
public abstract void eat();
}
//接口.
interface IB
{
void study();
}
interface IA
{
void teach();
}
class Student extends Person implements IB
{
//重写成员方法
public void eat(){
System.out.println("学生吃饭,喝饮料");
}
//重写接口的成员方法
public void study(){
System.out.println("学生爱学习,天天向上");
}
class Teacher extends Person implements IA
{
public void eat(){
System.out.println("老师吃饭,喜欢喝酒");
}
public void teach(){
System.out.println("老师讲课");
}
class Demo
{
public static void main(String[] args)
{
Person p = new Student();
p.sleep();
p.eat();
IB i = new Student();
i.study();
Person k = new Teacher();
k.sleep();
k.eat();
IA a = new Teacher();
a.teach();
|
|