手记

运用继承、多态、抽象类编写语言

package ex5;

public abstract class Person extends Aperson{
public abstract void say();
}
package ex5;

public class Chinese extends Person {
public void say()
{
System.out.println("Chinese speak Chinese");
}
}
package ex5;

public class American extends Person {
public void say()
{
System.out.println("Americans speak English");
}
}
package ex5;

public class Spain extends Person {
public void say()
{
System.out.println("Spains speak Spanish language");
}
}
package ex5;

public class Initail {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Person p1=new Chinese();
    Person p2=new American();
            Person p3=new Spain();
    p1.say();
    p2.say();
            p3.say();
}

}`

`

0人推荐
随时随地看视频
慕课网APP