成员函数方式
package cn.com.ch09;
class FatherTest{
public void pet(String str){
System.out.println(str);
}
}
public class SonTest extends FatherTest {
public void hitChild() {
System.out.println("这是使用接口实现");
}
public static void main(String[] args) {
SonTest son=new SonTest();
son.pet("这是直接继承");
son.hitChild();
}
}
另一种接口方式
package cn.com.ch09;
class FatherTest{
public void pet(String str){
System.out.println(str);
}
}
interface Stepfather{
public void hitChild();
}
public class SonTest extends FatherTest implements Stepfather{
public void hitChild() {
System.out.println("这是使用接口实现");
}
public static void main(String[] args) {
SonTest son=new SonTest();
son.pet("这是直接继承");
son.hitChild();
}
}