Java接口与继承
继承extends:
继承extends: public class Person { private String name; private int age; public Person() { } public Person(String name,int age) { this.name=name; this.age=age; } public void setName(String name) { this.name=name; } public String getName() { return name; } public void setAge(int age) { this.age=age; } public int getAge() { return age; } } public abstract class Sport extends Person{ public Sport() { } public Sport(String name,int age) { super(name,age); } public abstract void study(); } 接口interface: public interface English { public abstract void speak(); } public class PingPongSport extends Sport implements English{ public PingPongSport() { } public PingPongSport(String name,int age) { super(name,age); } @Override public void speak() { System.out.println(“PingPongSporter is Speaking English”); } @Override public void study() { System.out.println(“PingPongSporter is stduy PingPong skills”); } }

浙公网安备 33010602011771号