单选题class BitStuff {   BitStuff go() { System.out.print("bits "); return this; }   }   class MoreBits extends BitStuff {   MoreBits go() { System.out.print("more "); return this; }   public static void main(String [] args) {   BitStuff [] bs = {new BitStuf

题目
单选题
class BitStuff {   BitStuff go() { System.out.print("bits "); return this; }   }   class MoreBits extends BitStuff {   MoreBits go() { System.out.print("more "); return this; }   public static void main(String [] args) {   BitStuff [] bs = {new BitStuff(), new MoreBits()};   for( BitStuff b : bs)   b.go();   }   }   结果为:()
A

bits bits

B

bits more

C

more more

D

编译失败

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?() 

  • A、 foofoofoofoofoo
  • B、 foobarfoobarbar
  • C、 foobarfoofoofoo
  • D、 foobarfoobarfoo
  • E、 barbarbarbarbar
  • F、 foofoofoobarbar
  • G、 foofoofoobarfoo

正确答案:D

第2题:

现有  class Parser extends Utils {  public static void main (String  []  args)  {  try  {  System.out.print (new Parser () .getlnt ("42"))       }  catch (Exception e) {  System.out.println ("Exc") ;  }      }  int getlnt (String arg)  throws Exception  {     return Integer.parselnt (arg) ;      }      }  class Utils {  int getlnt ()  {  return 42;  }     }  结果是什么?()      

  • A、 42Exc
  • B、 Exc
  • C、 42
  • D、编译失败

正确答案:C

第3题:

classBitStuff{BitStuffgo(){System.out.print("bits");returnthis;}}classMoreBitsextendsBitStuff{MoreBitsgo(){System.out.print("more");returnthis;}publicstaticvoidmain(String[]args){BitStuff[]bs={newBitStuff(),newMoreBits()};for(BitStuffb:bs)b.go();}}结果为:()

A.bitsbits

B.bitsmore

C.moremore

D.编译失败


参考答案:B

第4题:

现有:  class Guy {String greet()    {return "hi";  }  }  class Cowboy extends Guy  (  String greet()    (  return "howdy  ¨;    )  )  class Surfer extends Guy  (String greet()    (return "dude! ";)) class Greetings  {  public static void main (String  []  args)    {  Guy  []  guys =  ( new Guy(), new Cowboy(), new Surfer()  );  for (Guy g:  guys) System.out.print (g.greet()};  }  }  结果为:() 

  • A、 hi howdy dude!
  • B、运行时异常被抛出。
  • C、第7行出现一个错误,编译失败。
  • D、第8行出现一个错误,编译失败。

正确答案:A

第5题:

class Guy{String greet(){return “hi“}}   class Cowboy extends Guy {String greet(){return“howdy”}}   class Surfer extends Guy {String greet(){return“dudel”}}  class Greetings{   public static void main (string[]args){   Guy[] guy= {new Guy(),new Cowboy(),new Surfer()};   for(Guy 0: guys)   System.out.print(g.green());  }   }   结果为:  

  • A、运行时异常被输出
  • B、第7行出现一个错误,编译失败
  • C、第8行出现一个错误,编译失败
  • D、hi hi hi
  • E、hi hawdy doude

正确答案:E

第6题:

现有:  class Parser (类)extends(继承) Utils {   public static void main(String [] args) {   System.out.print(输出打印)(new Parser().getInt("42"));  }   int getInt(String arg) {   return Integer.parseInt(arg);    }   }   class Utils {   int getInt(String arg) throws Exception { return 42; }  }   结果为:()  

  • A、 42
  • B、 编译失败。
  • C、 无输出结果。
  • D、 运行时异常被抛出。

正确答案:A

第7题:

class Flibitz {   public static void main(String [] args) {   int grop = 7;   new Flibitz().go(grop);   System.out.print(grop);   }   void go(int grop) {   if(++grop 〉 7) grop++;   System.out.print(grop);   }   }   结果为:()  

  • A、77
  • B、79
  • C、97
  • D、99

正确答案:C

第8题:

class BitStuff {   BitStuff go() { System.out.print("bits "); return this; }   }   class MoreBits extends BitStuff {   MoreBits go() { System.out.print("more "); return this; }   public static void main(String [] args) {   BitStuff [] bs = {new BitStuff(), new MoreBits()};   for( BitStuff b : bs)   b.go();   }   }   结果为:()  

  • A、bits bits
  • B、bits more
  • C、more more
  • D、编译失败

正确答案:B

第9题:

class Bird {  static void talk() { System.out.print("chirp "); }  }  class Parrot extends Bird {  static void talk() { System.out.print("hello "); }  public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot()};  for( Bird b : birds)  b.talk();  }  }  结果为:() 

  • A、chirp chirp
  • B、chirp hello
  • C、hello hello
  • D、编译失败

正确答案:A

第10题:

final class Tree {  private static String tree = "tree ";  String getTree() { return tree; }  }  class Elm extends Tree {  private static String tree = "elm "; public static void main(String [] args) {  new Elm().go(new Tree());  }  void go(Tree t) {  String s = t.getTree()+Elm.tree+tree+(new Elm().getTree());  System.out.println(s);  } }  结果为:() 

  • A、elm elm elm elm
  • B、tree elm elm elm
  • C、tree elm tree elm
  • D、编译失败

正确答案:D

更多相关问题