ITPUB??ì3
ITPUB论坛 » Java入门与认证版 » 问一个java 认证的考题


标题: 问一个java 认证的考题
离线 gaowudi
一般会员



精华贴数 0
个人空间 0
技术积分 578 (3276)
社区积分 0 (171039)
注册日期 2004-10-5
论坛徽章:0
      
      

发表于 2006-4-11 10:25 
问一个java 认证的考题

如下

Which three statements are true? (Choose three)
A. The default constructor initializes method variables.
B. The default constructor has the same access as its class.
C. The default constructor invoked the no-arg constructor of the superclass.
D. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors
for the class.

Answer: B, C, E

B怎么理解?


还有一题


如下

1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // ...code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }


Which two statements are true after line 15, before main completes? (Choose tw
o)

A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.

标准答案为C, D

不解, 谁可以解释一下啊?


只看该作者    顶部
离线 lang_m
新工作带来新问题


精华贴数 13
个人空间 0
技术积分 8915 (133)
社区积分 3326 (398)
注册日期 2001-11-1
论坛徽章:26
现任管理团队成员Heart of PUBITPUB新首页上线纪念徽章生肖徽章:羊  
      

发表于 2006-4-11 13:09 
1、因为缺省的构造器是public的,所以他的访问权限和类相同。
2、从根元素(一般指局部变量、对象变量等)无法到达a b 这两个对象,所以他们两个是无效的,可收集的


__________________
离开喧嚣的人群,繁华的都市,在宁静之中倾听天籁,呼吸.....不管你的工作再忙,也不要忘记你的朋友,他们是你一生的财富 你也许有很多Servlet的问题,看看Servlet Specification 2.4 ,很多东西就迎刃而解一本让你深入了解Java的书Component Development for the Java Platform
只看该作者    顶部
离线 gaowudi
一般会员



精华贴数 0
个人空间 0
技术积分 578 (3276)
社区积分 0 (171039)
注册日期 2004-10-5
论坛徽章:0
      
      

发表于 2006-4-11 14:38 
因为缺省的构造器是public的

虽然缺省的构造器是public的,但是缺省的class 声明不是public的吧

那样的话,应该不同啊


只看该作者    顶部
离线 lang_m
新工作带来新问题


精华贴数 13
个人空间 0
技术积分 8915 (133)
社区积分 3326 (398)
注册日期 2001-11-1
论坛徽章:26
现任管理团队成员Heart of PUBITPUB新首页上线纪念徽章生肖徽章:羊  
      

发表于 2006-4-11 14:40 
Re: 因为缺省的构造器是public的



QUOTE:
最初由 gaowudi 发布
虽然缺省的构造器是public的,但是缺省的class 声明不是public的吧

那样的话,应该不同啊


呵呵,你自己想想,没有任何不同


__________________
离开喧嚣的人群,繁华的都市,在宁静之中倾听天籁,呼吸.....不管你的工作再忙,也不要忘记你的朋友,他们是你一生的财富 你也许有很多Servlet的问题,看看Servlet Specification 2.4 ,很多东西就迎刃而解一本让你深入了解Java的书Component Development for the Java Platform
只看该作者    顶部
离线 carniege
冥王星酋长


精华贴数 0
个人空间 250
技术积分 20332 (45)
社区积分 13179 (111)
注册日期 2003-12-19
论坛徽章:80
现任管理团队成员开发板块每日发贴之星开发板块每日发贴之星2008年新春纪念徽章  
      

发表于 2006-4-11 20:55 
复习


__________________
兰叶春葳蕤,桂华秋皎洁。
欣欣此生意,自尔为佳节。
谁知林栖者,闻风坐相悦。
草木有本心,何求美人折。
只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问