class Guy { String greet() { return "hi "; } }  class Cowboy

题目
单选题
class Guy { String greet() { return "hi "; } }  class Cowboy extends Guy { String greet() { return "howdy "; } }  class Wrangler extends Cowboy { String greet() { return "ouch! "; } }  class Greetings2 {  public static void main(String [] args) {  Guy g = new Wrangler();  Guy g2 = new Cowboy();  Wrangler w2 = new Wrangler();  System.out.print(g.greet()+g2.greet()+w2.greet());  }  }  结果是什么?()
A

hi hi ouch!

B

hi howdy ouch!

C

ouch! howdy ouch!

D

编译失败

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

第1题:

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

第2题:

Assume that country is set for each class.  Given:  10. public class Money {  11. private String country, name;  12. public getCountry() { return country; }  13.}  and:  24. class Yen extends Money {  25. public String getCountry() { return super.country; }  26. }  27.  28. class Euro extends Money {  29. public String getCountry(String timeZone) {  30. return super.getCountry();  31. }  32. }  Which two are correct?()

  • A、 Yen returns correct values.
  • B、 Euro returns correct values.
  • C、 An exception is thrown at runtime.
  • D、 Yen and Euro both return correct values.
  • E、 Compilation fails because of an error at line 25.
  • F、 Compilation fails because of an error at line 30.

正确答案:B,E

第3题:

Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  

  • A、The code will fail to compile.
  • B、The constructor in a that takes an int as an argument will never be called as a result of constructing an     object of class b or c.
  • C、Class c has three constructors.
  • D、Objects of class b cannot be constructed.
  • E、At most one of the constructors of each class is called as a result of constructing an object of class c.

正确答案:B,C

第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题:

public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()

  • A、 public void aMethod() {}
  • B、 private void aMethod() {}
  • C、 public void aMethod(String s) {}
  • D、 private Y aMethod() { return null; }
  • E、 public X aMethod() { return new Y(); }

正确答案:C,E

第6题:

class Mineral {   static String shiny() { return "1"; }   }   class Granite extends Mineral {   public static void main(String [] args) {   String s = shiny() + getShiny();   s = s + super.shiny();   System.out.println(s);   }   static String getShiny() { return shiny(); }   }   结果为:()  

  • A、3
  • B、12
  • C、111
  • D、编译失败

正确答案:D

第7题:

public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public String getName(){         return name;      } }  public class Manager extends Employee{       public Manager(String name){          System.out.println(getName());      } }  执行语句new Manager(“smith”)后程序的输出是哪项?() 

  • A、 smith
  • B、 null
  • C、 编译错误
  • D、 name

正确答案:C

第8题:

class Guy { String greet() { return "hi "; } }  class Cowboy extends Guy { String greet() { return "howdy "; } }  class Wrangler extends Cowboy { String greet() { return "ouch! "; } }  class Greetings2 {  public static void main(String [] args) {  Guy g = new Wrangler();  Guy g2 = new Cowboy();  Wrangler w2 = new Wrangler();  System.out.print(g.greet()+g2.greet()+w2.greet());  }  }  结果是什么?() 

  • A、hi hi ouch!
  • B、hi howdy ouch!
  • C、ouch! howdy ouch!
  • D、编译失败

正确答案:C

第9题:

11. class Animal { public String noise() { return “peep”; } }  12. class Dog extends Animal {  13. public String noise() { return “bark”; }  14. }  15. class Cat extends Animal {  16. public String noise() { return “meow”; }  17. }  .....  30. Animal animal = new Dog();  31. Cat cat = (Cat)animal;  32. System.out.printIn(cat.noise());  What is the result?() 

  • A、 peep
  • B、 bark
  • C、 meow
  • D、 Compilation fails.
  • E、 An exception is thrown at runtime.

正确答案:E

第10题:

Which methods from the String and StringBuffer classes modify the object on which they are called?()  

  • A、The charAt() method of the String class.
  • B、The toUpperCase() method of the String class.
  • C、The replace() method of the String class.
  • D、The reverse() method of the StringBuffer class.
  • E、The length() method of the StringBuffer class.

正确答案:D

更多相关问题