单选题class Animal{ Animal getOne(){return new Animal();}}   class Dog extends Animal{   //insert code here   }   class AnimalTest{   public static void main(String[] args){   Animal[] animal={ new Animal(), new Dog()};   for(Animal a:animal){   Animal x= a.

题目
单选题
class Animal{ Animal getOne(){return new Animal();}}   class Dog extends Animal{   //insert code here   }   class AnimalTest{   public static void main(String[] args){   Animal[] animal={ new Animal(), new Dog()};   for(Animal a:animal){   Animal x= a.getOne();   }   }   }   和代码:   3a.Dog getOne() { return new Dog();}   3b.Animal getOne() { return new Dog();}   第3行中插入的哪项编译且运行无异常?
A

3a行或3b行

B

既非3a,也非3b

C

3a行

D

3b行


相似考题
更多“class Animal{ Animal getOne(){return new Animal();}}   class”相关问题
  • 第1题:

    classAnimal{AnimalgetOne(){returnnewAnimal();}}classDogextendsAnimal{//insertcodehere}classAnimalTest{publicstaticvoidmain(String[]args){Animal[]animal={newAnimal(),newDog()};for(Animala:animal){Animalx=a.getOne();}}}和代码:3a.DoggetOne(){returnnewDog();}3b.AnimalgetOne(){returnnewDog();}第3行中插入的哪项编译且运行无异常?

    A.3a行或3b行

    B.既非3a,也非3b

    C.3a行

    D.3b行


    参考答案:A

  • 第2题:

    使用VC6打开考生文件夹下的工程test19_1,此工程包含一个源程序文件test19_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:

    1:

    weight:5

    age:0

    2:

    weight:7

    age:9

    源程序文件test19_1.cpp 清单如下:

    include <iostream.h>

    class animal

    {

    public:

    /**************** found *******************/

    friend void setvalue(animal&,int);

    /**************** found *******************/

    void print()

    protected:

    int itsweight;

    int itsage;

    };

    void animal::print()

    {

    cout<<"weight:"<<itsweight<<end1;

    cout<<"age:"<<itsage<<end1;

    }

    void setvalue(animal &ta,int tw)

    {

    ta.itsweight=tw;

    ta.ihsage=0;

    }

    void setvalue(animal &ta,int tw, int tn)

    {

    ta.itsweight=tw;

    ta.itsage=tn;

    }

    void main()

    {

    /**************** found *******************/

    animal peppy

    setvalue(peppy,5);

    cout<<"1:"<<end1;

    peppy.print();

    setvalue(peppy,7,9);

    cout<<"2:"<<end1;

    peppy.print();

    }


    正确答案:(1)错误:缺少友元函数的声明 正确:添加友元函数的声明friend void setvalue(animal &intint); (2)错误:viod print(); 正确:void print(); (3)错误:animal peppy 正确:animal peppy;
    (1)错误:缺少友元函数的声明 正确:添加友元函数的声明friend void setvalue(animal &,int,int); (2)错误:viod print(); 正确:void print(); (3)错误:animal peppy 正确:animal peppy; 解析:(1)主要考查考生对于成员函数定义规则的掌握,成员函数必须先声明再使用,即使是友元函数也不例外;
    (2)主要考查考生对于关键字的掌握,空类型的关键字应用"void";
    (3)主要考查考生对于变量定义的掌握,该处缺少“;”。

  • 第3题:

    下列程序片段中,能通过编译的是( )。 A.public abstract class Animal{ public void speak;}S

    下列程序片段中,能通过编译的是( )。

    A.public abstract class Animal{ public void speak;}

    B.public abstract class Animal{ public void speak{);}

    C.public class Animal{ pubilc abstract void speak;}

    D.public abstract class Animal{ pubile abstract void speak{};}


    正确答案:A
    A。【解析】Java中一个类是一个abstract类的子类,它必须具体实现父类的abstract方法。如果一个类中含有abstract方法,那么这个类必须用abstract来修饰(abstract类也可以没有abstract方法)。有abstract方法的父类只声明,由继承它的子类实现。所以选A。

  • 第4题:

    classCatextendsAnimal{}对于下述代码说法正确的是()

    • A、Cat是Animal的子类
    • B、Animal是Cat的子类
    • C、Cat是Animal的超类
    • D、Animal一定是抽象类

    正确答案:A

  • 第5题:

    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

  • 第6题:

    多选题
    Given: 10. interface Jumper { public void jump(); } ...   20. class Animal {} ...   30. class Dog extends Animal {   31. Tail tail;   32. }   ...   40. class Beagle extends Dog implements Jumper{   41. public void jump() {}  42. }   ...   50. class Cat implements Jumper{   51. public void jump() {}   52. }. Which three are true?()
    A

    Cat is-a Jumper

    B

    Cat is-a Animal

    C

    Dog is-a Jumper

    D

    Dog is-a Animal

    E

    Beagle has-a Jumper

    F

    Cat has-a Animal

    G

    Beagle has-a Tail


    正确答案: E,B
    解析: 暂无解析

  • 第7题:

    多选题
    Which three demonstrate an “is a” relationship?()
    A

    public class X {  }     public class Y extends X { }

    B

    public interface Shape { }     public interface Rectangle extends Shape{ }

    C

    public interface Color { }     public class Shape { private Color color; }

    D

    public interface Species { }     public class Animal { private Species species; }

    E

    public class Person { }    public class Employee {      public Employee(Person person) { }

    F

    interface Component { }     class Container implements Component {   private Component[] children; }


    正确答案: A,F
    解析: 暂无解析

  • 第8题:

    多选题
    Which two demonstrate an “is a” relationship?()
    A

    public interface Person { }  public class Employee extends Person { }

    B

    public interface Shape { }  public class Employee extends Shape { }

    C

    public interface Color { }  public class Employee extends Color { }

    D

    public class Species { }  public class Animal (private Species species;)

    E

    interface Component { }  Class Container implements Component ( Private Component[ ] children;  )


    正确答案: D,B
    解析: 暂无解析

  • 第9题:

    多选题
    Which the two demonstrate an “is a” relationship?()
    A

    public interface Person {}  Public class Employee extends Person {}

    B

    public interface Shape {}  public interface Rectangle extends Shape {}

    C

    public interface Color {}  public class Shape { private Color color; }

    D

    public class Species {}  public class Animal { private Species species; }

    E

    interface Component {} Class Container implements Component {private Component [] children;


    正确答案: B,A
    解析: 暂无解析

  • 第10题:

    单选题
    interface Animal {  void soundOff();  }  class Elephant implements Animal {  public void soundOff() {  System.out.println(“Trumpet”);  }  }  class Lion implements Animal {  public void soundOff() { System.out.println(“Roar”);  }  }  class Alpha1 {  static Animal get( String choice ) {  if ( choice.equalsIgnoreCase( “meat eater” )) {  return new Lion();  } else {  return new Elephant();  }  }  }  Which compiles?()
    A

     new Animal().soundOff();

    B

     Elephant e = new Alpha1();

    C

     Lion 1 = Alpha.get(“meat eater”);

    D

     new Alpha1().get(“veggie”).soundOff();


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    现有:  interface Animal {       void eat () ;       }       //insert code here       public class HouseCat extends Feline {       public void eat() { }       }  和五个申明  abstract class Feline implements Animal { }  abstract  class  Feline  implements  Animal  {  void eat () ;  }  abstract class Feline implements Animal { public void eat();}  abstract class Feline implements Animal { public void eat() {}  }  abstract class Feline implements Animal { abstract public void eat();} 结果为:()
    A

    1

    B

    2

    C

    3

    D

    4


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    1. class Animal { Animal getOne() { return new Animal(); } }  2. class Dog extends Animal {  3. // insert code here   4. }  5.  6. class AnimalTest {  7. public static void main(String [] args) {  8. Animal [] animal = { new Animal(), new Dog() } ;  9. for( Animal a : animal) {  10. Animal x = a.getOne();  11. }  12. }  13. }  和代码:  3a. Dog getOne() {  return new Dog();  }  3b. Animal getOne() {  return new Dog();  }  第 3 行中插入的哪项将编译且运行无异常?()
    A

    3a行

    B

    3b行

    C

    3a行或3b行

    D

    既非3a,也非3b


    正确答案: C
    解析: 暂无解析

  • 第13题:

    1.classAnimal{AnimalgetOne(){returnnewAnimal();}}2.classDogextendsAnimal{3.//insertcodehere4.}5.6.classAnimalTest{7.publicstaticvoidmain(String[]args){8.Animal[]animal={newAnimal(),newDog()};9.for(Animala:animal){10.Animalx=a.getOne();11.}12.}13.}和代码:3a.DoggetOne(){returnnewDog();}3b.AnimalgetOne(){returnnewDog();}第3行中插入的哪项将编译且运行无异常?()

    A.3a行

    B.3b行

    C.3a行或3b行

    D.既非3a,也非3b


    参考答案:D

  • 第14题:

    有如下程序:

    nclude<iostream>

    using namespace std;

    class Animal{

    public:

    virtual char*getType()const{return“Animal”;}

    virtual char*getVoice()const{return“Voice”;}

    };

    class Dog:public Animal{

    public:

    char*getType()const{rgturn“Dog”;}

    char*getVoice()const{retum“Woof”;}

    };

    void type(Animal&A){cout<<a.getType();}

    void speak(AnimalA){cout<<a.getVoice();}

    int main(){

    Dog d.type(D);tout<<“speak”;speak(D);cout<<endl;

    return 0;

    }

    运行时的输出结果是【 】


    正确答案:Dog speak Voice
    Dog speak Voice 解析:基类中有两个虚函数getType( )和getVoiee( ),在派生类中同样也有。函数type和speak的形参都是Animal类的对象,但是一个是引用调用,另一个不是。当用Animal的派生类Dog类定义的对象调用这两个函数时,type函数会转向:Dog类中的成员函数,而speak函数不会。

  • 第15题:

    共用题干
    第三篇

    Animal Testing Controversy

    To paraphrase 18th-century statesman Edmund Burke,"All that is needed for the triumph of a misguided cause is that good people do nothing." One such cause now seeks to end biomedical research because of the theory that animals have rights ruling out their use in research.Scientists need to respond forcefully to animal rights advocates,whose arguments are confusing the public and thereby threatening advances in health knowledge and care.Leaders of the animal rights movement target biomedical research because it depends on public funding,and few people understand the process of health care research.Hearing allegations of cruelty to animals in research settings,many are perplexed that anyone would deliberately harm an animal.
    For example,a grandmotherly woman staffing an animal rights booth at a recent street fair was distributing a brochure that encouraged readers not to use anything that comes from or is animals一no meat,no fur,no medicines.Asked if she opposed immunizations,she wanted to know if vaccines come from animal research.When assured that they do,she replied,"Then I would have to say yes."Asked what will happen when epidemics return,she said,"Don't worry,scientists will find some way of using computers."Such well-meaning people just don't understand.
    Scientists must communicate their message to the public in a compassionate,understandable way一in human terms,not in the language of molecular biology.We need to make clear the connection between animal research and a grandmother's hip replacement,a father's bypass operation,a baby's vaccinations,and even a pet's shots.To those who are unaware that animal research was nee-- ded to produce these treatments,as well as new treatments and vaccines,animal research seems wasteful at best and cruel at worst.
    Much can be done.Scientists could"adopt"middle school classes and present their own re-search.They should be quick to respond to letters to the editor,lest animal rights misinformation go unchallenged and acquire a deceptive appearance of truth.Research institutions could be opened to tours,to show that laboratory animals receive humane care.Finally,because the ultimate stakeholders are patients,the health research community should actively recruit to its cause not only well-known personalities such as Stephen Cooper,who has made courageous statements about the value of animal research,but all who receive medical treatment.If good people do nothing there is a real possibility that an uninformed citizenry will extinguish the precious embers of medical progress.

    From the text we learn that Stephen Cooper is________.
    A:a well-known humanist
    B:a medical practitioner
    C:an enthusiast in animal rights
    D:a supporter of animal research

    答案:D
    解析:
    第一段中间提到“Scientists need to respond forcefully to animal rights advocates...”意思是科学家们需要采取行动回应这些动物权利的鼓吹者。这实际上就是一个呼吁,所以答案应该是A。
    第一段最后一句说,被误导的人们“听到医学实验残忍对待动物的指控时,许多人都不明白为什么有人会故意伤害动物”。第二段举了被误导女士的例子,她反对用动物来做研究。第三段最后一句,这些人认为“动物实验说得好是浪费,说得不好是残忍”。A 内容不完整。inevitable:不可避免的;vicious:危险的,所以选项B正确。
    该例子中,慈祥的妇人“encouraged readers not to use anything that comes from or is animals”,至于疫苗,如果来自动物她也抵制,认为流行病自有科学家们用计算机来解决。由此可见老人对科学的无知。第二段最后一句感叹“这些好心人根本就不明白”,所以答案为B。
    根据关键词“challenge from animal rights advocates”以及“scientists should”, 可以在最后两段中找出作者向科学家们提出的建议都有助于他们与公众更好的交流。很明显选项A合理,选项B、C、D在文中没有提到,不正确。
    最后一段“Finally,because the ultimate stakeholders are patients...Stephen Cooper, who has made courageous statements about the value of animal research”。从这句话我们知道,Cooper是个名人,也是患者,他曾经高度赞扬过动物研究的价值。由此可以推断他是支持动物研究的,正确答案是D。

  • 第16题:

    interface Animal {  void soundOff();  }  class Elephant implements Animal {  public void soundOff() {  System.out.println(“Trumpet”);  }  }  class Lion implements Animal {  public void soundOff() { System.out.println(“Roar”);  }  }  class Alpha1 {  static Animal get( String choice ) {  if ( choice.equalsIgnoreCase( “meat eater” )) {  return new Lion();  } else {  return new Elephant();  }  }  }  Which compiles?()  

    • A、 new Animal().soundOff();
    • B、 Elephant e = new Alpha1();
    • C、 Lion 1 = Alpha.get(“meat eater”);
    • D、 new Alpha1().get(“veggie”).soundOff();

    正确答案:D

  • 第17题:

    Which two demonstrate an “is a” relationship?()   

    • A、 public interface Person { }  public class Employee extends Person { }
    • B、 public interface Shape { }  public class Employee extends Shape { }
    • C、 public interface Color { }  public class Employee extends Color { }
    • D、 public class Species { }  public class Animal (private Species species;)
    • E、 interface Component { }  Class Container implements Component ( Private Component[ ] children;  )

    正确答案:D,E

  • 第18题:

    单选题
    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.


    正确答案: A
    解析: 暂无解析

  • 第19题:

    单选题
    在Java中,类Animal中的方法printA()定义如下:  public void printA() {    Int a=10;    Int result =10%3;    System.out.println(result); }  在类Dog中方法printA()定义如下:  public void printA() {   Int a=10;    System.out.println(a/3); }  Dog类的定义如下:  Class Dog extends Animal{…}.  Animal animal=new Dog();  animal.printA();  以上语句输出结果为()。
    A

     0

    B

     1

    C

     2

    D

    3

    E

    3.3333


    正确答案: D
    解析: 暂无解析

  • 第20题:

    单选题
    现有:  1. interface Animal {  2. void eat();  3. }  4.  5. // insert code here  6.  7. public class HouseCat extends Feline {  8. public void eat() { }  9. }   和五个声明:  abstract class Feline implements Animal { }  abstract class Feline implements Animal { void eat(); }  abstract class Feline implements Animal { public void eat(); }  abstract class Feline implements Animal { public void eat() { } }  abstract class Feline implements Animal { abstract public void eat(); }  分别插入到第5行,有几个可以通过编译?()
    A

    0

    B

    1

    C

    2

    D

    3


    正确答案: D
    解析: 暂无解析

  • 第21题:

    多选题
    10. interface Jumper { public void jump(); }  ......  20. class Animal {}  ......  30. class Dog extends Animal { 31. Tail tail; 32. }  ......  40. class Beagle extends Dog implements Jumper {  41. public void jump() { }  42. }  .......  50. class Cat implements Jumper {  51. public void jump() { }  52. }  Which three are true?()
    A

    Cat is-a Animal

    B

    Cat is-a Jumper

    C

    Dog is-a Animal

    D

    Dog is-a Jumper

    E

    Cat has-a Animal

    F

    Beagle has-a Tail

    G

    Beagle has-a Jumper


    正确答案: G,B
    解析: 暂无解析

  • 第22题:

    单选题
    现有:  1.  interface Animal  f      2.    void eat();      3.    }      4.  5.  // insert code here      6.  7. public class HouseCat implements Feline  {      8.    public void eat()    {  }     9.  }  和以下三个接口声明:  interface Feline extends Animal  (  )  interface Feline extends Animal  {void eat();    }  interface Feline extends Animal  {void eat()    {  }  }   分别插入到第5行,有多少行可以编译?
    A

      0

    B

      1

    C

      2

    D

      3


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    1. interface Animal {   2. void eat();   3. }   4.   5. // insert code here   6.   7. public class HouseCat implements Feline {   8. public void eat() { }   9. }   和以下三个接口声明:   interface Feline extends Animal { }   interface Feline extends Animal { void eat(); }   interface Feline extends Animal { void eat() { } }   分别插入到第 5 行,有多少行可以编译?()
    A

    0

    B

    1

    C

    2

    D

    3


    正确答案: C
    解析: 暂无解析

  • 第24题:

    单选题
    class Animal{ Animal getOne(){return new Animal();}}   class Dog extends Animal{   //insert code here   }   class AnimalTest{   public static void main(String[] args){   Animal[] animal={ new Animal(), new Dog()};   for(Animal a:animal){   Animal x= a.getOne();   }   }   }   和代码:   3a.Dog getOne() { return new Dog();}   3b.Animal getOne() { return new Dog();}   第3行中插入的哪项编译且运行无异常?
    A

    3a行或3b行

    B

    既非3a,也非3b

    C

    3a行

    D

    3b行


    正确答案: A
    解析: 暂无解析