Change line 2 to: public int a;
Change line 2 to: protected int a;
Change line 13 to: public Sub() { this(5); }
Change line 13 to: public Sub() { super(5); }
Change line 13 to: public Sub() { super(a); }
第1题:
给出下列代码,如何使成员变量m被方法fun( )直接访问?Class Test{private int m;public static void fun( ){} }
A.将private int m改为protected int m
B.将private int m改为public int m
C.将private int m改为static int m
D.将private int m改为int m
第2题:
已知:Manager extends Employee观察:public Manager(String n,double s,int year,int month,int day) { super(n,s,year,month,day); bonus=0; }其中super是 ( )
A.Object类
B.Manager类
C.Employee类
D.Class类
第3题:
有如下类声明:
class MyClass
{
int i;
private: int j;
protected:int k;
public:int m, n;
};
其中,私有成员的数量为 【 9 】 。
第4题:
若有以下程序: #include <iostream> using namespace std; class Base { private: int x; protected: int y; public: int z; void setx(int i) { x=i; int getx () { return x; } }
A.1,2,3,4
B.产生语法错误
C.4,3,2,1
D.2,3,4,5
第5题:
下面程序中错误之处是 ______。
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
}
第6题:
给出下列代码,如何使成员变量m被方法fun( )直接访问? class Test{ private int m; public static void fun( ){ … } }
A.将private int m改为protected int m
B.将private int m改为public int m
C.将private int m改为static i
D.将private int m改为int m
第7题:
若有以下程序: #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
第8题:
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
第9题:
请找出下列程序中错误之处 ______。
#include<iostream.h>
class A{
private:
int x1;
protected:
int x2;
public:
int x3;
};
class B:public A{
private:
int y1;
protected:
int y2;
public:
int y3;
void disp(){cout<<x1<<y1<<end1:} //A
void set(int i) {x2=i;} //B
};
void main() {
B bb;
bb.x3=10; //C
bb.y3=10; //D
}
A.A
B.B
C.C
D.D
第10题:
设有类定义如下:
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m = new MyOver(10);
}
MyOver(int i){
super(i);
}
MyOver(String s, int i){
this(i);
//Here
}
}
以下哪条语句可以安排在//Here处 ?
A.MyOver m = new MyOver();
B.super();
C.this("Hello",10);
D.Base b = new Base(10);