Java认证考试

public class X {   public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   oa[0] = null;   return o;   }   }   When is the float object created in line 3, eligible for garbage collection?()  A、 Just af

题目

public class X {   public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   oa[0] = null;   return o;   }   }   When is the float object created in line 3, eligible for garbage collection?()  

  • A、 Just after line 5.
  • B、 Just after line 6.
  • C、 Just after line 7.
  • D、 Just after line 8(that is, as the method returns).
参考答案和解析
正确答案:C
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

在如下源代码文件Test.java中, 哪个是正确的类定义?()

A.public 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.public class


正确答案:BD

第2题:

有以下程序:include using namespace std; class Base { public: Base() { K=0; } int

有以下程序:

include<iostream>

using namespace std;

class Base

{

public:

Base()

{

K=0;

}

int x;

};

class Derivedl:virtual public Base

{

public:

Derivedl()

{

x=10;

}

};

class Derived2:virtua1 public Base


正确答案:20。
20。 解析: 本题中,虽然Derived1和Derived2由于引入了虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derived1中修改,还是在类Derived2中修改,都是直接对这惟一拷贝进行操作。本题程序执行语句“Derived obi;”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived1的构造函数使得x=10,再执行类Derived2的构造函数,使得x=20。最后输出x的值为20。

第3题:

有以下程序: included using namespace std; class Base { public: Base( ) { x=0; }

有以下程序:

included<iostream>

using namespace std;

class Base

{

public:

Base( )

{

x=0;

}

int x;

};

class Derived1:virtual public Base

{

public:

Derived1( )

{

x=10;

}

};

class Derived2:virtual public Base

{

public:

Derived2( )

{

x=20;

}

};

class Derived: public Derived1,protected Derived2

{ };

int main( )

{

Derived obj;

cout<<obj. x<<endl;

return 0;

}

该程序运行后的输出结果是______。


正确答案:20
20 解析:本题考核虚基类。本题中,虽然Derived 1和Derived 2都是由共同的基类x派生而来的,但由于引入虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derired 1中修改,还是在类Derived 2中修改,都是直接对这唯一拷贝进行操作。本题程序执行语句“Derived obj;”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived 1的构造函数使得x=10,再执行类Derived 2的构造函数,使得x=20。最后输出x的值为20。

第4题:

有如下程序: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。

第5题:

在下列源代码文件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。

第6题:

下列类头定义中,错误的是( )。

A.class x { .... }

B.public x extends y { .... }

C.public class x extends y { .... }

D.class x extends y implements y1 { .... }


正确答案:B

第7题:

若有以下程序:include using namespace std;class Base{public: Base ( ) {x=0; } in

若有以下程序: #include <iostream> using namespace std; class Base { public: Base ( ) { x=0; } int x; }; class Derivedl : virtual public Base { public: Derivedl () { x=10; } }; class Derived2 : virtual public Base { public: Derived2 () { x=20; } }; class Derived : public Derivedl,protected Derived2{ }; int main ( ) { Derived obj; cout<<obj .x<<end1; return 0; } 该程序运行后的输出结果是 ( )。

A.20

B.30

C.10

D.0


正确答案:A
解析:本题中,虽然Derivedl和Derived2都是由共同的基类x派生而来的,但由于引入了虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derived1修改,还是在类Derived2中修改,都是直接对这惟一拷贝进行操作。本题程序执行语句“Derivedobj”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived1的构造函数,使得x=10,再执行类Derived2的构造函数,使得x=20。最后输出x的值为20。

第8题:

下列哪个方法可用于创建一个可运行的类? ( )

A.public class X implements Runable {public void run(){...,.,}}

B.public class X implements Thread {public void run(){......}}

C.public class X implements Thread {public int run(){……}}

D.public class X implements Runable {protected void run(){.....}}


正确答案:A

第9题:

有以下程序: include class A { intx; public: A(int a) { x=a;} friend class B;

有以下程序:

include<iostream.h>

class A

{

int x;

public:

A(int a)

{

x=a;

}

friend class B;

}

class B{

public:

void print(A a){

a. x--;

cout<<a.x<<end1;

}

};

void main()

{

A a(10);

B b;

b.print(a) ;

}

程序执行后的输出结果是【 】。


正确答案:9
9 解析:本题考核友元类的应用。在程序中,类B是类A的友元类,因此,在类B的所有成员函数中均可访问类A的任何成员。在main()中,先定义类A的一个对象a(10)和类B的一个对象b。然后通过对象b调用其成员函数print输出对象a的私有成员x的值减1即9。

第10题:

若有以下程序:include using namespace std; class Base public: Base() { x=0;} in

若有以下程序: #include <iostream> using namespace std; class Base public: Base() { x=0; } int x; }; class Derivedl: virtual public Base public: Derived1() { x=10; } }; class Derived2: virtual public Base publici Derived2() x=20; }; class Derived :public Derived1,protected Derived2 {}; int main() Derived obj; cout<<obj.x<<end1; return 0; } 该程序运行后的输出结果是

A.20

B.30

C.10

D.0


正确答案:A
解析:本题考核虚基类的应用。本题中,虽然Derived1和Derived2都是由共同的基类x派生而来的,但山于引入了虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derived1修改,还是在类Derived2中修改,都是直接对这惟一拷贝进行操作。本题程序执行语句“Derivedobj”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived1的构造函数使得x=10,再执行类Derived2的构造函数,使得x=20。最后输出x的值为20。

更多相关问题