peep
bark
meow
Compilation fails.
An exception is thrown at runtime.
第1题:
( 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 】 。
第2题:
有如下程序:
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;
}
运行时的输出结果是【 】
第3题:
有如下程序:
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;
}
程序的输出结果是______。
第4题:
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”)后程序的输出是哪项?()
第5题:
下列程序片段中,能通过编译的是( )。
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{};}
第6题:
阅读下面代码 abstract class Person { public Person(String n) { name=n; } public______String getDescription(); public String getName() { return name; } private String name; } 在下画线处应填入的修饰符是
A.static
B.abstract
C.protected
D.final
第7题:
下列程序片段中,能通过编译的是( )。
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( ){};}
第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(){}}
第9题:
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?()
第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?()