publicabstractclassAnimal{publicabstractvoidEat();publicvoid

题目
单选题
publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}以下关于C#代码地描述正确的是()。
A

该段代码正确

B

代码错误〃因为类中存在非抽象方法

C

代码错误〃因为类中方法没有实现

D

通过代码Animalan=newAnimal;可以创建一个Animal对象

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

第1题:

单选题
publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}以下关于C#代码地描述正确的是()。
A

该段代码正确

B

代码错误〃因为类中存在非抽象方法

C

代码错误〃因为类中方法没有实现

D

通过代码Animalan=newAnimal;可以创建一个Animal对象


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

第2题:

publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}以下关于C#代码地描述正确的是()。

  • A、该段代码正确
  • B、代码错误〃因为类中存在非抽象方法
  • C、代码错误〃因为类中方法没有实现
  • D、通过代码Animalan=newAnimal;可以创建一个Animal对象

正确答案:A

第3题:

阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。

【java代码】
class invoice{
public void printInvoice( ){

System.out.println ( "This is the content of the invoice!");
}
}
class Decorator extends Invoice {

protected Invoice ticket;

public Decorator(lnvoice t){

ticket = t;
}
public
void printInvoice( ){

if(ticket != null)
(1) ;

}
}
class HeadDecorator extends Decorator{

public HeadDecorator(lnvoice t){

super(t);
}

public void printInvoice ( ){

Systent.out.println( "This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {

public FootDecorator(Invoice t){

super(t);
}

public void printlnvoice( ){

( 3) ;

Systent.out.println( "This is the footnote of the invoice! ");
}
}
Class test {

public static void main(String[] args){

Invoice t =new Invioce( );

Invoice ticket;

ticket= (4) ;

ticket.printInvoice( );

Systent.out.println(“------------------“);

ticket= (5) ;

ticket.printInvoice( );
}
}
程序的输出结果为:

This is the header of the invoice!

This is the content of the invoice!

This is the footnote of the invoice!

----------------------------

This is the header of the invoice!

This is the footnote of the invoice!


答案:
解析:
(1) ticket.printInvoice()
(2) ticket.printInvoice()

(3) ticket.printInvoice()

(4) new FootDecorator(new

第4题:

以下关于C#代码的说法正确的是()publicabstractclassAnimal{publicabstractvoidEat();publicvoidSleep(){}}

A、代码编译错误,因为类中方法没有实现

B、代码编译错误,因为类中存在非抽象方法

C、该段代码正确

D、通过代码”Animalan=newAnimal();”可以创建一个Animal对象


参考答案:C

第5题:

阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。

[说明]

①定义私有数据成员code、english分别用于表示考生的编号、英语成绩,它们都是int型的数据。

②完成成员函数void Student::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下:

输入编号:

英语成绩:

计算机成绩:

③利用已实现的类Student的成员函数,完成函数void firstname(Student *A[],int uum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。

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

include < iostream. h >

class Student

(1)

int computer;

int total;

public

void getinformation( );

void computesum( );

int getcode( );

int gettotalscore( );

~Student( );

};

void Student: :getinformation( )

{

(2)

cout <<"英语成绩:";

cin> >english;

cout <<"计算机成绩:";

cin > > computer;

void Student:: computesum ( )

total = english + computer;

cout <<"编号" << code <<"总分:" <<total << endl;

int Student::getcode( )

return code;

}

int Student:: gettotalscore ( )

{

return total;

}

void firstname(Student * A[] ,int num)

{

(3)

tempsum = ( * A[0] ). gettotalscore( );

for( int i=1; i <num; i++)

{

if ( ( ( * A[i] ). gettotalscore( ) ) > tempsum)

{

tempcode = ( * A[i] ). getcode( );

tempsum = ( * A[i] ). gettotalscore( );

}

}

cout <<"总分最高者--" << tempcode <<":" << tempsum <<endl;

}

void main( )

{

Student * A[3];

int i,n =3

for(i=0;i<n;i ++)

A[i] = new Student;

A[i] -> getinformation( )

for(i=0;i<n;i ++)

{

A[i] -> computesum( )

firstname ( A,3 );

}


正确答案:(1)itn code; int english; (2)cout<<"输入编号:"; cin>>code; (3)int tempcode tempsum; tempcode=(*A[0]). getcode();
(1)itn code; int english; (2)cout<<"输入编号:"; cin>>code; (3)int tempcode, tempsum; tempcode=(*A[0]). getcode(); 解析:本题是对C++程序设计的综合考查,其设计类的成员及成员函数的定义与调用,数据的输入输出,for循环语句,if条件判断语句等多个知识点,注意(3)中指针数组的使用,指针数组是一组指针,每一个成员都按照指针的操作规则,但是整个访问规则仍然使用数组下标方式,如A[0]指的是第一个指针,而*A[0]是取出第一个指针指向的内容。

第6题:

如果不能使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基数继承的成员,下列程序没有使用多态机制,其输出结果是( ) 。

#include

using namespace std;

class Base{

public:

Void print(){cout<< ‘B’;}};

class Derived: public Base{

public

void print(){cout<< ‘D’;}}

int main()

{

Derived*pd=new Dreived);

Base*pb=pd;

pb->print();

pd->print();

delete pd;

return 0;

}


正确答案:

(x+8)