The code will deadlock.
The code may run with no output.
An exception is thrown at runtime.
The code may run with output “0 6”.
The code may run with output “2 0 6 4‟.
The code may ruin with output “0 2 4 6”.
第1题:
下列程序的运行结果是【 】。
include <iostream. h>
class test
{
private:
int num;
public:
test()
int TEST() {return num+100;}
~test()
};
test::test(){num=0;}
test::~test(){cout<<"Destructor is active"<<endl;}
void main()
{
test x[3]
cout<<x[1]. TEST()<<endl;
}
第2题:
阅读以下说明和Java代码,回答问题1和问题2,将解答填写在对应栏内。
【Java代码】
class usethread implements (1) {
int num
usethread(int n){
num=n;
}
public void (2) {
for(int i=0;i<3;i++)
System.out.println("running:"+num);
System.out.println("finished:"+num);
}
public class multhread{
public static void main(String args[]) (3) InterruptedException{
Thread m1=new Thread(new usethread(1));
Thread m2=new Thread(new usethread(2));
m1.start();
m2.start();
m1.join();
m2.join();
}
}
【问题1】
补充完整上面Java代码中(n)处。
【问题2】
写出上面Java代码运行的结果。
第3题:
类A定义如下: class A { private int x=10; int getx() { return x;} } class B extends A { private int x=15; //需要覆盖getx()方法 } 在下述方法中可以在类B中覆盖getx()方法的是 ( )
A.int getx(){…}
B.int getx(float f){…}
C.float getx(){…}
D.double getx(float f){…}
第4题:
下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void
A.Exiting main Destructor is active Destructor is active Destructor is active
B.Exiting main Destructor is active Destructoris active
C.Exiting main Destructoris active
D.Exiting main
第5题:
下列程序编译错误,是由于划线处缺少某个语句,该语句是______。
include<iostream.h>
class A
{
private:
int numl;
public:
A( ):numl(0){}
A(int i):numl(i){}
};
class B
{
private:
int num2;
public:
B( ):num2(0){}
B(int i):num2(i){}
int my_math(A obj1, B obj2);
};
int B::my_math(A obj1,B obj2)
{
return(obj1.numl+obj2.num2);
}
void main(void)
{
A objl(4);
B obj,obj2(5);
cout<<"obj1+obj2:"<<obj.my_math(obj1,obj2);
}
第6题:
( 30 )在程序的下划线处应填入的选项是
public class Test _________{
public static void main(String args[]){
Test t = new Test();
Thread tt = new Thread(t);
tt.start();
}
public void run(){
for(int i=0;i<5;i++){
system.out.println( " i= " +i);
}
}
}
A ) implements Runnable
B ) extends Thread
C ) implements Thread
D ) extends Runnable
第7题:
Which statements concerning the following code are true?() class a { public a() {} public a(int i) { this(); } } class b extends a { public boolean b(String msg) { return false; } } class c extends b { private c() { super(); } public c(String msg) { this(); } public c(int i) {} }
第8题:
Which two demonstrate an “is a” relationship?()
第9题:
public class Parent { int change() {…} } class Child extends Parent { } Which methods can be added into class Child?()
第10题:
The code will fail to compile.
The constructor in a that takes an int as an argument will never be called as a result of constructing an object of class b or c.
Class c has three constructors.
Objects of class b cannot be constructed.
At most one of the constructors of each class is called as a result of constructing an object of class c.
第11题:
public interface Person { } public class Employee extends Person { }
public interface Shape { } public class Employee extends Shape { }
public interface Color { } public class Employee extends Color { }
public class Species { } public class Animal (private Species species;)
interface Component { } Class Container implements Component ( Private Component[ ] children; )
第12题:
The code will deadlock.
The code may run with no output.
An exception is thrown at runtime.
The code may run with output “0 6”.
The code may run with output “2 0 6 4‟.
The code may ruin with output “0 2 4 6”.
第13题:
下列程序的运行结果是______。
include<iostream.h>
class test
{
private:
int hum;
public:
test( );
int TEST( ){return num+100;)
~test( );
};
test::test( ){num=0;)
test::~test( ){cout<<"Destructor is active"<<endl;)
void main( )
{
test x[3];
cout<<x[1].TEST( )<<endl;
}
第14题:
根据下面的主程序,完成类的一种构造函数的最简单形式。
include<iostream.h>
class base
{
private:
int num;
public:
______;
};
void main( )
{
base try(6);
}
第15题:
阅读以下说明和C++码,填入(n)处。
[说明]
建立一个分数类,使之具有下述功能:建立构造函数,它能防止分母为0,当分数不是最简形式时进行约分以及避免分母为负数。
[C++代码]
include<iostream.h>
include<math.h>
class Num
{
public:
Num (int a,int b);
private:
int num1;
int num2;
}:
Num:: Num (int a,int b)
{
if( (1) )
{
cout<<"ERROR"<<endl;
return;
}
int min=fabs(a)<fabs (b)?fabs (a): fabs (b);
int x=1;
for (int i=1;i<=min;i++)
if( (2) )
x=i;
a/=X;
b/=x;
if( (3) )
{
a=-a;
b=-b;
}
(4)
(5)
}
第16题:
A.final int num1 = 10;
B.static int num2 = 20;
C.abstract int num3 = 30;
D.private int num4 = 40;
第17题:
如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。
include<iostream.h>
class test
{
private:
int hum;
public:
test(int);
void show( );
};
test::test(int n){num=n;}
test::show( ){cout<<num<<endl;}
void main( )
{
test T(10):
T.show( );
}
第18题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第19题:
Which Man class properly represents the relationship "Man has a best friend who is a Dog"?()
第20题:
What produces a compiler error?()
第21题:
Compilation fails.
An exception is thrown at runtime.
Synchronizing the run() method would make the class thread-safe.
The data in variable “x” are protected from concurrent access problems.
Declaring the doThings() method as static would make the class thread-safe.
Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.
第22题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第23题:
public interface Person {} Public class Employee extends Person {}
public interface Shape {} public interface Rectangle extends Shape {}
public interface Color {} public class Shape { private Color color; }
public class Species {} public class Animal { private Species species; }
interface Component {} Class Container implements Component {private Component [] children;
第24题:
class A { public A(int x) {} }
class A {} class B extends A { B() {} }
class A { A() {} } class B { public B() {} }
class Z { public Z(int) {} } class A extends Z {}