1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return

题目
多选题
1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return new SuperFoo(); 4. }  5. }  6.  7. class Foo extends SuperFoo {  8. //insert code here  9. }   下面哪三项分别插入到第8行,可以编译?()
A

int doStuff() { return 42; }

B

int doStuff(int x) { return 42; }

C

Foo doStuff(int x) { return new Foo(); }

D

SuperFoo doStuff(int x) { return new Foo(); }

参考答案和解析
正确答案: B,A
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?() 

  • A、 float getVar() { return x; }
  • B、 public float getVar() { return x; }
  • C、 public double getVar() { return x; }
  • D、 protected float getVar() { return x; }
  • E、 public float getVar(float f) { return f; }

正确答案:B,D

第2题:

1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?() 

  • A、 An exception is thrown at runtime.
  • B、 Compilation fails because of an error in line 7.
  • C、 Compilation fails because of an error in line 4.
  • D、 Compilation succeeds and no runtime errors with class A occur.

正确答案:C

第3题:

public class Something {

public int addOne(final int x) {

return ++x;

}

}

这个比较明显。


正确答案:

 

错。int x 被修饰成final,意味着x 不能在addOne method 中被修改。

第4题:

1. public class returnIt (  2. returnType methodA(byte x, double y) (  3. return (short) x/y * 2;  4. )  5. )   What is the valid returnType for methodA in line 2?()  

  • A、 Int
  • B、 Byte
  • C、 Long
  • D、 Short
  • E、 Float
  • F、 Double

正确答案:F

第5题:

现有:   1. class Synapse {    2.    protected int gap() { return 7; }    3. }   4.     5. class Creb extends Synapse {    6.   // insert code here   7. }    分别插入到第 6 行,哪三行可以编译?()

  • A、 int gap() { return 7; }
  • B、 public int gap() { return 7; }
  • C、 private int gap(int x) { return 7; }
  • D、 protected Creb gap() { return this; }
  • E、 public int gap() { return Integer.getInteger ("42"); }

正确答案:B,C,E

第6题:

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

  • A、 Line 4 of class Target can be changed to return i++;
  • B、 Line 2 of class Target can be changed to private int i = 1;
  • C、 Line 3 of class Target can be changed to private int addOne() {
  • D、 Line 2 of class Target can be changed to private Integer i = 0;

正确答案:D

第7题:

interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?() 

  • A、 s 14
  • B、 s 16
  • C、 s 10
  • D、 Compilation fails.
  • E、 An exception is thrown at runtime.

正确答案:D

第8题:

1. public class ReturnIt {  2. return Type methodA(byte x, double y) {  3. return (long)x / y * 2;  4. }  5. }  What is the narrowest valid returnType for methodA in line2?()  

  • A、 int
  • B、 byte
  • C、 long
  • D、 short
  • E、 float
  • F、 double

正确答案:F

第9题:

1. public class Test {  2. public  T findLarger(T x, T y) {  3. if(x.compareTo(y) > 0) {  4. return x;  5. } else {  6. return y;  7. }  8. }  9. }  and:  22. Test t = new Test();  23. // insert code here  Which two will compile without errors when inserted at line 23?()

  • A、 Object x = t.findLarger(123, “456”);
  • B、 int x = t.findLarger(123, new Double(456));
  • C、 int x = t.findLarger(123, new Integer(456));
  • D、 int x = (int) t.findLarger(new Double(123), new Double(456));

正确答案:A,C

第10题:

1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return new SuperFoo(); 4. }  5. }  6.  7. class Foo extends SuperFoo {  8. //insert code here  9. }   下面哪三项分别插入到第8行,可以编译?()

  • A、int doStuff() { return 42; }
  • B、int doStuff(int x) { return 42; }
  • C、Foo doStuff(int x) { return new Foo(); }
  • D、SuperFoo doStuff(int x) { return new Foo(); }

正确答案:A,C,D

更多相关问题