CMS专题

多选题1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()Apublic int blipvert(int x) { return 0; }Bpri

题目
多选题
1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()
A

public int blipvert(int x) { return 0; }

B

private int blipvert(int x) { return 0; }

C

private int blipvert(long x) { return 0; }

D

protected long blipvert(int x, int y) { return 0; }

E

protected int blipvert(long x) { return 0; }

F

protected long blipvert(long x) { return 0; }

G

protected long blipvert(int x) { return 0; }

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

第1题:

有如下类定义:

class Point{

public:

Point(int xx=0,int yy=0):x(xx),y(yy) { }

private:

int x,y;

};

class Circle:public Point{

public:

Circle(int r):radius(r) { }

private:

int radius;

};

派生类Circle中数据成员的个数是( )。

A、3

B、1

C、5

D、2


答案:A
解析:本题考查默认构造函数和带参数的构造函数,题目中定义一个对象a(2)以及对象数组b[3],共执行3次构造函数,对象指针不调用构造函数。


第2题:

有如下程序:include using namespace std;Class x{protected: int a;public: x() {a=

有如下程序: #include <iostream> using namespace std; Class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<

A.1

B.123

C.242

D.244


正确答案:D
解析:本题程序中引入了虚基类。在主函数中,执行语句“y obj;”时,先执行虚基类x的构造函数,使a=1,然后执行类x1的构造函数,使a=2,并输出值2。再执行类x2的构造函数,使a=4,并输出值4。最后执行类y的构造函数,输出值4。

第3题:

有如下类声明: class Base{ protected: int amount; public: Base(int n=0):araount(n){ } int getAmount( )const{retum amount;} }; class Derived:public Base{ protected; int value; public: Derived(int m,int n):value(n1),Base(n){ } int getData( )const{return value+amount;} }; 已知x是一个Derived对象,则下列表达式中正确的是

A.x.value+x.getAmount( )

B.x.getData( )-x.getAmount( )

C.x.getData( )-x.amount

D.x.value+x.amount


正确答案:B

第4题:

有如下程序: include class x { protected: int a; public:x(){ a=1;} }; class x

有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。

A.1

B.123

C.242

D.244


正确答案:D
解析:本题程序中引入了虚基类。在主函数main中,执行语句“yobj;”时,先执行虚基类x的构造函数,使a=1;然后执行类x1的构造函数,使a=2,并输出值2;再执行类x2的构造函数,使a=4,并输出值4;最后执行类y的构造函数,输出值4。

第5题:

若有以下程序:include using namespace std;class A{private: int x;protected: int

若有以下程序: #include <iostream> using namespace std; class A { private: int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx () { return x; }; class B : protected A { public: void setvalue(int a, int b, int c) { setx (a); y=b; z=c; } void display() { cout<<getx ( ) <<", "<<y<<", "<<z<<", "<<end1; } }; int main () { B obj; obj.setvalue(5, 6, 7); obj.display ( ); return 0; } 程序运行后的输出结果是( )。

A.产生语法错误

B.7,6,5

C.5,6,7

D.7,5,6


正确答案:C
解析:本题考核保护继承中对类成员的访问权限。①在保护继承中,基类公有成员和保护成员都以保护成员身份出现在派生类中,而基类私有成员不可访问。②基类的公有成员和保护成员被继承以后作为派生类的保护成员,这样,派生类的其他成员可以直接访问它们。③由保护派.生的类声明的对象,不能访问任何基类的成员。在本题中,基类A中的数据成员y和函数setx,经过保护继承以后,在派生类B中成为保护成员,派生类B的对象不能访问它们。而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

第6题:

在下列源代码文件Test.java中,正确定义类的代码是( )。

A.pblic class test { public int x=0; public test(int x) { this. x=x;} }

B.public class Test { public int x=0; public Test(int x) { this. x=x;} }

C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }

D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }


正确答案:B
解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

第7题:

有如下类声明: class Base{ protected: int amount; public: Base(int n=0):amount(n){} int getAmountconst{retum amount;} }; class Derived:public Base{ protected: int value; public: Derived(int m,int n):value(m),Base(n){} int getDataconst{return value+amount;} }: 已知x是一个Derived对象,则下列表达式中正确的是( )。

A.x.value+X.getAmount

B.x.getData一x.getAmount

C.x.getData一x.amount

D.x.value+X.amount


正确答案:B
本题考查公有继承中派生类对象对基类的访问属性。在公有继承中,派生类对象只能访问基类的公有成员,而不能}方问基类的保护成员和私有成员。题中x是派生类的对象,只能访问基类中公有的Base和getAmount成员,而不能访问保护类型的amount成员,故选项C、D错误。而类对象对类成员的访问也存在类似的情况,即类对象只能访问类的公有成员,而value是Derived的保护成员,所以A选项也错误。故答案为B。

第8题:

已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?()

A.private void fun( int n ){ //...}

B.void fun ( int n ){ //... }

C.protected void fun ( int n ) { //... }

D.public void fun ( int n ) { //... }


正确答案:CD

第9题:

下面程序运行的结果是()。includeusing namespace std;class A{ protected:int a; pub

下面程序运行的结果是( )。 #include<iostream> using namespace std; class A{ protected: int a; public: void input(int i) {a=i;} }; class B{ protected: int a; public: void input(int j) {a=j;} }; class C: public A, public B { int x; public: void input() {x=A::a * B::a;cout<<x<<endl;} }; void main() { C c; c.A::input(5); c.B::input(8); c.input(); }

A.5

B.8

C.40

D.编译出错


正确答案:C
解析:用成员名限定法来消除二义性,故答案为C。

第10题:

下面程序中错误之处是 ______。 include classA{private:intxl;protected:intx2;publ

下面程序中错误之处是 ______。

include<iostream.h>

class A{

private:

int xl;

protected:

int x2;

public:

int x3;

};

class B: public A{

private:

int b1;

protected:

int b2;

public:

int b3;

void disp(){cout<<x1<<b2<<end1;} //A

void set(int i){x3=i;} //B

};

void main()

B bb;

bb. a3=10 //C

bb. b3=10 //D

}


正确答案:√
1

更多相关问题