Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:超宋侍?关于类和方法 [Re:andy04911]
whyuaou





发贴: 21
积分: 0
于 2005-08-15 12:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
andy04911 wrote:
Base b = new Extension( );就调用了两次子类中的add( )方法.

可是我还有点概念上的不明白,Base b//就要使用一次add( )
然后new Extension( )//又要使用一次add( )

那如果实例化子类生成一个对象,如:
Extension c = new Extension( );岂不是也要Extension c//一次
然后new Extension( );一次??
可是事实上实例话对象只会调用一次构造函数啊,可是原题调用了两次.....//晕~

我刚学java,超级菜鸟,可能看书不够仔细有概念遗漏,请前辈们点拨一二,谢谢.^_^

实例化时的确只会调用一个构造函数一次,但该例在实例化的时候, 首先调用父类的构造方法,然后调用扩展类的构造方法,这样才能完成实例化。由于父类和起扩展类的构造方法中都会调用add()方法,所以add()方法被调用两次,并不是调用一个构造方法两次。




话题树型展开
人气 标题 作者 字数 发贴时间
23793 超菜问题,关于类和方法 truthawp 718 2005-08-04 12:26
21000 Re:超菜问题,关于类和方法 why 42 2005-08-04 13:20
21333 Re:超菜问题,关于类和方法 truthawp 205 2005-08-04 20:06
21006 Re:超菜问题,关于类和方法 why 304 2005-08-04 20:24
21043 Re:超菜问题,关于类和方法 truthawp 409 2005-08-05 20:42
20969 Re:超菜问题,关于类和方法 meteorping 20 2005-08-06 11:33
20938 Re:超菜问题,关于类和方法 truthawp 85 2005-08-06 11:54
21445 Re:超菜问题,关于类和方法 acl2005 108 2005-08-06 16:00
20894 Re:超菜问题,关于类和方法 jameszhang 39 2005-08-06 18:03
21474 Re:超菜问题,关于类和方法 acl2005 43 2005-08-07 07:14
21196 Re:超菜问题,关于类和方法 javalean 1364 2005-08-07 16:01
20842 Re:超菜问题,关于类和方法 truthawp 193 2005-08-08 11:36
21185 Re:超菜问题,关于类和方法 javalean 110 2005-08-08 12:15
20781 Re:超菜问题,关于类和方法 truthawp 16 2005-08-08 16:39
21297 Re:超菜问题,关于类和方法 yqt 25 2005-08-04 15:35
20803 Re:超菜问题,关于类和方法 why 164 2005-08-08 19:31
21366 Re:超菜问题,关于类和方法 acl2005 25 2005-08-08 23:30
21175 Re:超菜问题,关于类和方法 飞翔的梦想 21 2005-08-10 08:55
21031 Re:超宋侍?关于类和方法 andy04911 304 2005-08-11 00:50
20766 Re:超宋侍?关于类和方法 jameszhang 360 2005-08-11 19:14
20906 Re:超宋侍?关于类和方法 whyuaou 470 2005-08-15 12:43
20441 Re:超菜问题,关于类和方法 why 134 2005-08-22 07:29
21086 Re:超菜问题,关于类和方法 ch_zh_80 85 2005-08-14 10:38
20745 Re:超菜问题,关于类和方法 truthawp 106 2005-08-14 12:31
21116 Re:超菜问题,关于类和方法 ch_zh_80 59 2005-08-15 11:31
21159 Re:超菜问题,关于类和方法 hxz5830 213 2005-08-16 15:48
20901 Re:超菜问题,关于类和方法 whyuaou 369 2005-08-17 15:22
21062 Re:超菜问题,关于类和方法 zj1290 331 2005-08-20 13:34
21247 Re:超菜问题,关于类和方法 truthawp 34 2005-08-04 22:28
20950 Re:超菜问题,关于类和方法 why 258 2005-08-04 22:57
20948 Re:超菜问题,关于类和方法 brianlove 52 2005-08-22 01:48
21061 Re:超菜问题,关于类和方法 zj1290 23 2005-08-22 10:38
21331 Re:超菜问题,关于类和方法 zj1290 160 2005-08-22 15:23
21281 Re:超菜问题,关于类和方法 truthawp 17 2005-08-04 23:27
21466 Re:超菜问题,关于类和方法 zhangp_happy 236 2005-08-05 14:50
21175 Re:超菜问题,关于类和方法 yqt 133 2005-08-05 16:30
21441 Re:超菜问题,关于类和方法 zhangp_happy 158 2005-08-06 10:04
20989 Re:超菜问题,关于类和方法 truthawp 551 2005-08-05 18:43
21150 Re:超菜问题,关于类和方法 dabing 95 2005-08-05 18:55

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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