关于147中的119?、126?、144?、

bigheadsheep 2003-11-09 04:52:09
119. Which will declare a method that is available to all
members of the same package and can be referenced without an
instance of the class? //完全不明白,能说说具体的判断根据么??
A.abstract public void methoda();
B.public abstract double methoda();
C.static void methoda(double d1){};
D.public native double methoda(){};
E.protected void methoda(double d1){};

Given:
public class OuterClass {
private double d1 = 1.0;
//insert code here , line 2
}
You need to insert an inner class declaration at line2. Which
two inner class declarations are valid? (Choose Two) //判断选择的原因是什么??要是有什么关于inner class的点睛之处,方便的告诉一声
A.static class InnerOne {
public double methoda() {return d1;}
}
B.static class InnerOne {
static double methoda() {return d1;}
}
C.private class InnerOne {
public double methoda() {return d1;}
}
D.protected class InnerOne {
static double methoda() {return d1;}
}
E.public abstract class InnerOne {
public abstract double methoda();
}

144. Which statements about static inner classes are true? (Choose Two)
A. A static inner class requires a static initializer.
B. A static inner class requires an instance of the enclosing
class.
C. A static inner class has no reference to an instance of the
enclosing class.
D. A static inner class has access to the non-static members
of the outer class.
E. Static members of a static inner class can be referenced
using the class name of the static inner class.
我看的有两种答案,c d和c e ,改选哪个??


小弟知道学艺不精,恳请帮忙,谢了
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dulang200x 2003-11-14
  • 打赏
  • 举报
回复
119的意思是定义一个方法只能被同一包中的类访问,且可以不用借助引用就可以访问其中的变量,根据上面的条件所以必须是无访问控制符,且必须是static!所以选c
第二个题目,当然是选c,e了,静态内类不能访问外类的非静态变量!
144当然是选c。e了!,原因跟上面那题差不多!
xiaoyuantian 2003-11-14
  • 打赏
  • 举报
回复
119下面的那题:
A和B是定义的静态内部类,要用外部类的d1 时先要实例化,所以错!
D是个非静态的内部类不能包含任何静态的方法,所以错,
那么就只能选C和E了啊!
NightRanger 2003-11-13
  • 打赏
  • 举报
回复
119.
问题问的是定义“同一包内可以看到的”和“不须创建实例就可调用的”一个方法,
即考“访问修饰符”和“static关键字”两个知识点,访问修饰符可以选public,default,protected都可满足要求,不能用private,后者要求必须有static来修饰。所以答案为:c

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧