当前位置: 技术问答>java相关
情急,请教,帮忙!
来源: 互联网 发布时间:2015-10-12
本文导语: 这道题选什么?为什么这么选? 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 tw...
这道题选什么?为什么这么选?
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();
}
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();
}
|
我认为 选c和e;
Inner Class 中的成员不能声明为 static;只有在顶层类中才可声明static;
Inner Class 中的成员不能声明为 static;只有在顶层类中才可声明static;
|
选C
*************************************
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;}//错!非静态内类不得拥有静态成员,除非是final的
}
B: public class InnerOne{
static double methoda() {return d1;}//错!理由同上
}
C: private class InnerOne{
double methoda() {return d1;}//ok,内类可以拥有private修饰
}
D: static class InnerOne{
protected double methoda() {return d1;}//错!静态内类无信封实例,看不到d1;
}
E: abstract class InnerOne{
public abstract double methoda();//感觉不对,无理由
}
***************************************
*************************************
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;}//错!非静态内类不得拥有静态成员,除非是final的
}
B: public class InnerOne{
static double methoda() {return d1;}//错!理由同上
}
C: private class InnerOne{
double methoda() {return d1;}//ok,内类可以拥有private修饰
}
D: static class InnerOne{
protected double methoda() {return d1;}//错!静态内类无信封实例,看不到d1;
}
E: abstract class InnerOne{
public abstract double methoda();//感觉不对,无理由
}
***************************************
|
选A吧