publicclassTest{publicstaticvoidmain(String[]args){WomanaWoman=newWoman();aWoman.growHeight(120);System.out.println(aWoman.getHeight());}}classWomanextendsHuman{/***newmethod*/publicHumangiveBirth(){System.out.println("Givebirth");return(newHuman());}}classHuman{/***accessor*/publicintgetHeight(){returnthis.height;}/***mutator*/publicvoidgrowHeight(inth){this.height=this.height+h;}/***breath*/publicvoidbreath(){System.out.println("hu...hu...");}privateintheight;}Human定义在Woman后面也能被Woman类查找到。。。和c/c++的先声明再使用完全不一样啊。。。java新手java的名字查找是怎么样的?网上没找到这方面的资料。。。
添加回答
举报
0/150
提交
取消