Topic: 莫名其妙的包到底怎么啦? |
Print this page |
1.莫名其妙的包到底怎么啦? | Copy to clipboard |
Posted by: chenxiang0207 Posted on: 2005-04-17 13:45 package package1; public class TestPackage1 { String getString( ){ return "This is package1 class." ; } } package package2; import package1.TestPackage1; public class TestPackage2 extends TestPackage1 { public String getString( ){ return "This is package2 class."; } } package package1; import package2.TestPackage2; public class Test { public static void main(String[] args) { TestPackage2 test = new TestPackage2( ); System.out.println(test.getString( )); } } 程序为什么输出 "This is package1 class."?程序不是加载了 package2.TestPackage2,这样不是应该输出"This is package2 class."的吗?我调了半天了依旧没有发现,就是不知道为什么?本人刚入JAVA门槛,不知其所然,希望那位高人能替我解释一下,小弟不甚感激!!! |
2.Re:莫名其妙的包到底怎么啦? [Re: chenxiang0207] | Copy to clipboard |
Posted by: VirusCamp Posted on: 2005-04-17 21:14 楼主胡说,我照你的,c&p 看看结果: F:\java\temp>java package1.Test This is package2 class. 我想楼主不会是路径错误,如果是路径错,根本不能执行. 根据语法, public String getString( ){ return "This is package2 class."; } 将覆盖 String getString( ){ return "This is package1 class." ; } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |