- class Demo
- {
- public static void main(String[] args)
- {
- MiniDog mini = new MiniDog();
- mini.call();
- }
- }
- class Dog
- {
- private String getName(){
- return "Dog";
- }
-
- public String cry(){
- return "wang-wang";
- }
-
- public void call(){
- System.out.println("I'm " + getName() + " " + cry());
- }
- }
- class MiniDog extends Dog
- {
- private String getName()
- {
- return "Mini";
- }
-
- public String cry()
- {
- return "WOO";
- }
- }
复制代码 结果:I'm Dog WOO 杂不是:I'm Mini WOO
|