当前位置: 技术问答>java相关
scjp 高手请进!!!!!
来源: 互联网 发布时间:2015-05-15
本文导语: 69. Given: 1. class BaseClass{ 2. private float x= 1.0f; 3. protected void setVar (float f) {x = f;} 4. } 5. class SubClass exyends BaseClass { 6. private float x = 2.0f; 7. //insert code here 8. } Which two are valid examples of method overriding? (...
69. Given:
1. class BaseClass{
2. private float x= 1.0f;
3. protected void setVar (float f) {x = f;}
4. }
5. class SubClass exyends BaseClass {
6. private float x = 2.0f;
7. //insert code here
8. }
Which two are valid examples of method overriding? (Choose Two)
A. void setVar(float f) {x = f;} //这个选项是对的吗? 这也是覆盖啊!
B. public void setVar(int f) {x = f;}
C. public void setVar(float f) {x = f;}
D. public double setVar(float f) {x = f;}
E. public final void setVar(float f) {x = f;}
F. protected float setVar() {x=3.0f; return 3.0f; }
71. Click the exhibit button:
1. class A {
2. public byte getNumber () {
3. return 1;
4. }
5. }
6.
7. class B extends A {
8. public short getNumber() { // 我怎么不可以把他看成重载
9. return 2;
10. }
11.
12. public static void main (String args[]) {
13. B b = new B ();
14. System.out.printIn(b.getNumber())
15. }16. }
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14.
1. class BaseClass{
2. private float x= 1.0f;
3. protected void setVar (float f) {x = f;}
4. }
5. class SubClass exyends BaseClass {
6. private float x = 2.0f;
7. //insert code here
8. }
Which two are valid examples of method overriding? (Choose Two)
A. void setVar(float f) {x = f;} //这个选项是对的吗? 这也是覆盖啊!
B. public void setVar(int f) {x = f;}
C. public void setVar(float f) {x = f;}
D. public double setVar(float f) {x = f;}
E. public final void setVar(float f) {x = f;}
F. protected float setVar() {x=3.0f; return 3.0f; }
71. Click the exhibit button:
1. class A {
2. public byte getNumber () {
3. return 1;
4. }
5. }
6.
7. class B extends A {
8. public short getNumber() { // 我怎么不可以把他看成重载
9. return 2;
10. }
11.
12. public static void main (String args[]) {
13. B b = new B ();
14. System.out.printIn(b.getNumber())
15. }16. }
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14.
|
1, 因为 default 类型比 protected 类型范围小, default 只能被同一package的类调用,而protected 还可以被子类调用.
在进行override时, overriding 函数的类型不能比overrided的函数"窄"!
2.机不是override ,也不是 overload, if override, the return type should be the same; if overload , the argument type should be different!
在进行override时, overriding 函数的类型不能比overrided的函数"窄"!
2.机不是override ,也不是 overload, if override, the return type should be the same; if overload , the argument type should be different!
|
1、public>protected>default>private
重写不能更加严格。
2、返回类型不能做为重载的因素。
重写不能更加严格。
2、返回类型不能做为重载的因素。
|
1:BE(注意Overriding和Overloading的区别)
2:C(Overriding和Overloading都不允许有相同参数和函数名而有不同返回值。要不然,若你写:String a = "hello" + func(temp);其中的func(temp)的返回值用什么?)
2:C(Overriding和Overloading都不允许有相同参数和函数名而有不同返回值。要不然,若你写:String a = "hello" + func(temp);其中的func(temp)的返回值用什么?)
|
1,默认的权限是frendly,比protect小,而overriding不能覆盖成更smaller
2,我觉得是c,overloading的话,光是返回值不一样是不够的
2,我觉得是c,overloading的话,光是返回值不一样是不够的
|
69.默认为default的权限,default