Java认证考试

class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  } class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here 16. }   Which two are valid examples of method overriding?()     A、 Void setVar(float 

题目

class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  } class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here 16. }   Which two are valid examples of method overriding?()     

  • A、 Void setVar(float f) {x = f;}
  • B、 Public void setVar(int f) {x = f;}
  • C、 Public void setVar(float f) {x = f;}
  • D、 Public double setVar(float f) {x = f;}
  • E、 Public final void setVar(float f) {x = f;}
  • F、 Protected float setVar() {x=3.0f; return 3.0f; }
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

N-ISDN是指?( )

A.BRI

B.PRI


正确答案:B

第2题:

为完成下面的程序,应在划线处填入的语句是includeusingnamespace std;class Base{pri

为完成下面的程序,应在划线处填入的语句是 #include<iostream> using namespace std; class Base { private: int x; public: Base (int i) { x=i; } ~Base(){} }; class Derived:public Base { public: ______________//完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }

A.Derived(int i):Base(i){}

B.Derived(){}

C.void Derived (int i):Base(i){}

D.Derived(int i){Base(i);}


正确答案:A
解析:本题考核派生类中的构造函数。程序中,类Derived是基类Base的公有派生。在类Derived的构造函数应该包括调用基类构造函数使基类的数据成员得以初始化。

第3题:

在Visual FoxPro中,基类的最小属性集为Class、BaseClass、ClassLibrary和______。


正确答案:ParentClass
ParentClass

第4题:

以下程序调试结果为:class Base{Base(){int i = 100;System.out.print (i);}}public class Pri extends Base{static int i = 200;public static void main(String argv[]){Pri p = new Pri();System.out.print(i);}}

A.编译错误

B.200

C.100200

D.100


正确答案:C

第5题:

12 一个给定的数值由左边开始升位到右边第 N 位,如

0010<<1 == 0100

或者

0001 0011<<4 == 0011 0000

请用 C 或者 C++或者其他 X86 上能运行的程序实现。

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

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

附加题(只有在完成以上题目后,才获准回答)

In C++, what does "explicit" mean? what does "protected" mean?

explicit

C++ Specific

This keyword is a declaration specifier that can only be applied to

in-class constructor declarations. Constructors declared explicit will not

be considered for implicit conversions. For example:

class X {

public:

explicit X(int); //legal

explicit X(double) { //legal // ... }

};

explicit X::X(int) {} //illegal

An explicit constructor cannot take part in implicit conversions. It can

only be used to explicitly construct an object. For example, with the class

declared above:

void f(X) {}

void g(int I)

{

f(i); // will cause error

}

void h()

{

X x1(1); // legal

}

The function call f(i) fails because there is no available implicit

conversion from int to X.

Note It is meaningless to apply explicit to constructors with multiple

arguments, since such constructors cannot take part in implicit conversions.

END C++ Specific

protected

C++ Specific —>

protected: [member-list]

protected base-class

When preceding a list of class members, the protected keyword specifies

that those members are accessible only from member functions and friends of

the class and its derived classes. This applies to all members declared up

to the next access specifier or the end of the class.

When preceding the name of a base class, the protected keyword specifies

that the public and protected members of the base class are protected

members of the derived class.

Default access of members in a class is private. Default access of members

in a structure or union is public.

Default access of a base class is private for classes and public for

structures. Unions cannot have base classes.

For related information, see public, private, friend, and Table of Member

Access Privileges.

END C++ Specific

Example

// Example of the protected keyword

class BaseClass {

protected: int protectFunc();

};

class DerivedClass : public BaseClass

{ public:

int useProtect() { protectFunc(); } // protectFunc accessible from

derived class

};

void main()

{

BaseClass aBase;

DerivedClass aDerived;

aBase.protectFunc(); // Error: protectFunc not accessible

aDerived.protectFunc(); // Error: protectFunc not accessible in derived

class } How do you code an infinite loop in C?


正确答案:
 

第6题:

分析下列程序中类MyClass的定义class BaseClass{publicinti;}classMyClass:BaseClass//继承BaseClass{publicnewinti;}则下列语句在Console上的输出为_______.()MyClassy=newMyClass();BaseClassx=y;//父类指针x指向子类对象x.i=100;//操作父类i Console.WriteLine("{0},{1}"

A、0,0

B、100,100

C、0,100

D、100,0


参考答案:D

第7题:

假设objtb是类MyTextBox的一个实例对象,类MyTextBox是基类TextBox的一个直

接子类,那么objtb对象的BaseClass属性值是_____。


正确答案:
TextBoxTextBox是Visual FoxPro的一个基类,指的是文本框; BaseClass是基类最小属性集中的一个属性,用来指定基类名,即指定当前类从哪个Visual FoxPro基类派生而来。本题中,由于类MyTextBox是基于TextBox派生出来的,而objtb是类MyTextBox的对象,因此objtb对象的BaseClass属性值是TextBox。

第8题:

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

class Base

class D1

class D2

class D3

fin Base

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

include<iostream.h>

class Base

{

public:

Base(){cout<<"class Base"<<endl;}

void f(){cout<<"f in Base"<<endl;}

};

class D1:virtual public Base

{

public:

D1(){cout<<"class D1"<<endl;}

void f(){cout<<"f in D1"<<endl;}

};

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

class D2:public Base

{

public:

D2(){cout<<"class D2"<<endl;}

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

class D3::public D1,public D2

{

public:

D3(){cout<<"class D3"<<endl;}

};

void main()

{

D3 d;

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

d.f();

}


正确答案:(1)错误:class D2:public Base 正确:class D2:virtual public Base (2)错误:class D3::public D1public D2 正确:class D3:public D1public D2 (3)错误:d.f(); 正确:d.Base::f();
(1)错误:class D2:public Base 正确:class D2:virtual public Base (2)错误:class D3::public D1,public D2 正确:class D3:public D1,public D2 (3)错误:d.f(); 正确:d.Base::f(); 解析:(1)主要考查考生对虚基类的理解,虚基类可以解决二义性的问题,其定义方式是在继承列表中使用virtual关键字,使用虚基类可以避免程序运行中对基类函数调用的不惟一;
(2)主要考查考生对类的定义方法的掌握,“::”为作用域符,此处应该使用“:”,因为后面是继承列表;
(3)主要考查考生对虚基类函数调用过程的理解,只有使用“:”限定才能访问基类函数,否则将会调用自身的函数,如果该类没有该函数的定义,则会自动调用其父类的该函数,所以必须使用“::”符号。

第9题:

当你编译运行下列程序代码,会得到什么结果?

private class Base{ Base(){ int i = 100; System.out.println(i); } }

public class Pri extends Base{ staticint i = 200;

public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } }

A.这段代码不能通过编译

B.输出200

C.输出100和200

D.输出100


正确答案:A

第10题:

ThenetworkadministratorisaddinganewN1KvtothevCenter,however,theadministratordoesnotseethenewswitchunderthenetworkingtabofvCenter.

TheadministratorissuesthefollowingcommandontheVSMtotroubleshoot:

VSM#showsvsconnections

connectionVC:

ipaddress:10.10.10.30

remoteport:80

protocol:vmware-vimhttps

certificatE.default

datacenternamE.DC1

DVSuuiD.67323050a6d24964-9e1c5f49e3af5599

configstatus:Disabled

operationalstatus:Disconnectedsyncstatus:-

version:-

Whenattemptingtofixtheissue,thefollowingerrorisseen:

VSM-PRI-188#conf

VSM-PRI-188(config)#svsconnectionVC

VSM-PRI-188(config-svs-conn)#connect

ERROR:[VMWARE-VIM]Extensionkeywasnotregisteredbeforeitsuse

Whatisthecauseoftheerror?()


参考答案:D

更多相关问题