Phone基类: package ven; public class Phone { public Phone(){} public void call(String name){ System.out.println("给"+name+"打电话"); } }
AIPhone子类:
package ven; public class AIPhone extends Phone{ @Override //重载注解,提示校验子类重写父类call()方法 public void call(String name) { //用super关键字调用父类的call()方法,不用再复制父类同样方法 super.call(name); //子类独有的扩展功能描述 System.out.println("同时开启视频功能……"); } }
测试类:
package ven; public class Test { public static void main(String[] args) { AIPhone iP= new AIPhone(); iP.call("张三"); } }