日期:2014-05-20 浏览次数:20698 次
结果:(我怎么理解的是注释的结果啊) Frog swim Frog speak Frog eat Frog grow Frog eat //Amphibian eat Amphibian grow Frog eat // Amphibian eat import static org.greggordon.tools.Print.*; class Amphibian { protected void swim() { println("Amphibian swim"); } protected void speak() { println("Amphibian speak"); } void eat() { println("Amphibian eat"); } static void grow(Amphibian a) { println("Amphibian grow"); a.eat(); } } public class Frog17 extends Amphibian { @Override protected void swim() { println("Frog swim"); } @Override protected void speak() { println("Frog speak"); } @Override void eat() { println("Frog eat"); } static void grow(Amphibian a) { println("Frog grow"); a.eat(); } public static void main(String[] args) { Frog17 f = new Frog17(); // call overridden base-class methods: f.swim(); f.speak(); f.eat(); // upcast Frog17 to Amphibian argument: f.grow(f); //调导出类的方法,f向上转型为基类型,然后导出类中a.eat()是不是应该调基类的eat()啊 // upcast Frog17 to Amphibian and call Amphibian method: Amphibian.grow(f);//调基类方法,参数向上转型基类型,然后a.eat()不应该是掉基类的eat么 } }
import static org.greggordon.tools.Print.*; class Component1 { Component1() { println("Component1()"); } } class Component2 { Component2() { println("Component2()"); } } class Component3 { Component3() { println("Component3()"); } } class Root { Component1 c1root=new Component1() ; Component2 c2root; Component3 c3root; Root() { println("Root()"); } } class Stem extends Root { Component1 c1stem; Component2 c2stem=new Component2(); Component3 c3stem; Stem() { println("Stem()"); } public static void main(String[] args) { Stem s = new Stem(); } }