A hundred years ago many kids died at an early age.
A.Right
B.Wrong
C.Not mentioned
第1题
为完成下面的程序,应在划线处填入的语句是 #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.Denved(int i){Base(i);}
第2题
为完成下面的程序,应在划线处填入的语句是 #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);}
第3题
为完成下面的程序,应在划线处填入的语句是()。 #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.voidDerived(int i):Base(0){}
D.Derived(int i){Base(i);}
第4题
根据下面的主程序,完成类的一种构造函数的最简单形式。
include<iostream.h>
class base
{
private:
int num;
public:
______;
};
void main()
{
base try(6);
}
第5题
第6题
阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。否则请说明编译 失败的原因。 public class Demo { public static void main(String[] args) { Base b1=Base.getBaseInstance1(); System.out.print(b1.getS()); Base b2=Base.getBaseInstance2(); System.out.print(b2.getS()); } } abstract class Base { private static String s = "base"; public static Base getBaseInstance1() { return new Base() { public String getS() { return s; } }; } public static Base getBaseInstance2() { return new Base("good") { public String getS() { return s; } }; } public Base() { } public Base(String s) { this.s = s; } public abstract String getS(); }
第7题
【分录题】下面的程序定义了一个线程TimeThread,该线程每隔1秒钟输出显示一次当前系统时间,在main方法中使用TimeThread类创建3个新线程,并启动这些线程,请将下面的程序填写完整。 import java.util.*; class TimeThread implements (1) { public void run() { while (true) { Date currentTime = new Date(); try { (2) ; // 休眠1秒钟 } catch (Exception e) {System.out.println(e.toString());} System.out.println(Thread.currentThread().getName()+": "+currentTime); } } } public class Ex2 { public static void main(String[] args){ String[] names={"first","second","third"}; TimeThread myThread = new TimeThread(); for(int i=0;i<3;i++){ thread threadobj="new" thread(mythread,names[i]); (3) ; 启动线程 }>
第8题
在下面横线上填上适当的语句,完成程序。
include<iostream>
using namespace std;
class Base
{
int x;
public:
Base(int i){x=i;}
~Base(){}
);
class Derived:public Base
{
public:
______//完成类Derive构造函数的定义
};
iht main()
{
Derived obj
第9题
(8-2)(1)在包qzy.jsu中定义了如下类Base: package qzy.jsu; class Base{ public void show1() { } protected void show2() { } void show3() { } private void show4() {}; } (2)在qzy.jsu包中定义了如下类Sub,则 ①处的正确代码是()。 package qzy.jsu; public class Sub { public void show() { ① } }
A、new Base().show1();
B、new Base().show2();
C、new Base().show3();
D、new Base().show4();
第10题
重写下面的程序,给每个类增加一个析构函数,并使类之间的关系如附件图所示,再 写出程序的输出结果。 #include <iostream> using namespace std; class base1 { public: base1() { cout << "constructing base1" << endl; } }; class base2 { public: base2() { cout << "constructing base2 " << endl; } }; class derived1 :public base2, virtual public base1 { public: derived1() { cout << "constructing derived1" << endl; } }; class derived2 :public base2, virtual public base1 { public: derived2() { cout << "constructing derived2" << endl; } }; class Derived3 :public derived1, virtual public derived2 { public: Derived3() { cout << "constructing derived3" << endl; } }; int main() { Derived3 obj; return 0; }
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!