当前位置: 技术问答>java相关
sun测试题———选什么,为什么这么选?谢谢(java初学者请教)
来源: 互联网 发布时间:2015-10-15
本文导语: 2. Given: public class OuterClass { private double d1 = 1.0; //insert code here } You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.) A: class InnerOne{ publi...
2. Given:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)
A: class InnerOne{
public static double methoda() {return d1;}
}
B: public class InnerOne{
static double methoda() {return d1;}
}
C: private class InnerOne{
double methoda() {return d1;}
}
D: static class InnerOne{
protected double methoda() {return d1;}
}
E: abstract class InnerOne{
public abstract double methoda();
}
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)
A: class InnerOne{
public static double methoda() {return d1;}
}
B: public class InnerOne{
static double methoda() {return d1;}
}
C: private class InnerOne{
double methoda() {return d1;}
}
D: static class InnerOne{
protected double methoda() {return d1;}
}
E: abstract class InnerOne{
public abstract double methoda();
}
|
选c,e。
试一下就知道了。
1、a,b,d都会提示以下错误:
non-static variable d1 cannot be referenced from a static context
也就是在静态(static)类和静态方法中是不能访非静态变量的。
2、同时,b还提示:
inner classes cannot have static declarations,
也就是非静态类中不能定义静态方法。
试一下就知道了。
1、a,b,d都会提示以下错误:
non-static variable d1 cannot be referenced from a static context
也就是在静态(static)类和静态方法中是不能访非静态变量的。
2、同时,b还提示:
inner classes cannot have static declarations,
也就是非静态类中不能定义静态方法。
|
c e?
|
I see
|
静态环境不能引用动态成员。
非静态Inner Class不能拥有static成员
非静态Inner Class不能拥有static成员
|
llsoft(天堂鱼) 讲得挺好的。