CMS专题

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

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

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

第1题:

Text 2 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 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's 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 needed 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 research. 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.

第46题:The author begins his article with Edmund Burke\'s words to

A. call on scientists to take some actions.

B. criticize the misguided cause of animal rights.

C. warn of the doom of biomedical research.

D. show the triumph of the animal rights movement.


正确答案:A

第2题:

( 12 )有如下程序:

#include <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 {return "Dog" ; }

char* getVoice ( ) const {return "Woof"}

};

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

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

int main ( ) {

Dog d; type ( d ) ; cout<<" speak" ; speak ( d ) ; cout<<endi;

return 0;

}

运行时的输出结果是【 12 】 。


正确答案:

第3题:

有如下程序: include using namespaee std;class Animal{ public: virtual char*g

有如下程序:

include<iostream>

using namespaee std;c lass Animal{

public:

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

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

};

class Dog:public Animal{

public:

char*getType( )const{return"Dog";}

char*getVoice( )eonst{return"Woof";}

};

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

void speak(Animal A) {eout<<a.getVoice( );}

int main( ){

Dog d;type(D) ;cout<<"speak";speak(D) ;cout< return 0;

}

程序的输出结果是______。


正确答案:Dog SpeakVoice
Dog SpeakVoice 解析:派生类继承基类,并重新定义了基类的虚函数。void type(Animal&A) 是对象引用作为函数参数,传递的是地址,是“地址调用”,故a.getType( )调用的是派生类重新定义后的get—Type( )成员函数。void speak(Animal A) 是对象作为函数参数,是“传值调用”,在进行函数调用时,将派生类对象赋值给基类对象。但是,对象a只能调用派生类继承自基类的成员。故在a.getVoice( )中调用的是基类的虚函数getVoice( ),打印“Voive”。

第4题:

有如下程序:

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函数不会。

第5题:

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

第6题:

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

第7题:

It can be inferred from the passage that all of the following are ways of producing new strains of influenza viruses EXCEPT______.

A. two influenza viruses in the same animal recombining

B. animal viruses recombining with human viruses

C. two animal viruses recombining in one animal

D. two animal viruses recombining in a human


正确答案:D
[解析] 见第三段,根据句意可知选项D为正确答案。

第8题:

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

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

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

C.public class Animal{ public abstract void speak();}

D.public abstract class Animal{ public abstract void speak(){}}


正确答案:A

第9题:

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

第10题:

下列程序片段中,能通过编译的是( )。 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。

更多相关问题