更多"#include<iostream.h> class A int"的相关试题:
[单项选择]若类A和类B的定义如下:
class A
int i,j;
public:
int geti ( )
return i;
;
class B : public A
int k;
public:
void make ( )
k=i*j;
;
则上述定义中非法的语句是
A. k=i*j;
B. int k;
C. return i;
D. void make()
[单项选择]若类A和类B的定义如下
class A
int i,j;
public:
int geti( )
return i;
;
class B:public A
int k:
public:
void make( )
k=i*j;
;
则上述定义中非法的语句是
A. k=i*j
B. int k;
C. return i;
D. void make()
[单项选择]若类A和类B的定义如下:
class A
int i,j;
public:
int geti( )
return i;
;
class B : public A
int k;
public:
void make( )
k=i*j;
;
则上述定义中非法的表达式是( )。
A. k=i*j
B. int k;
C. return i;
D. void make()
[填空题]按注释完成程序
public class Leaf
private int i = 0; //此属性值用于检验
Leaf increment( ) //定义方法increment( ),返回值是Leaf类的对象
i++;
return (1) ;//将当前对象的地址作为返回值返回
void print( )
System.out.println(" i = " + i);
public static void main(String args[])
Leaf x = (2); //创建Leaf类的对象x
x.increment( ).increment( ).increment( ).print( );
//多次调用方法increment( ),返回的都是x的地址,i 值表示调用次数
输出结果为 i = (3)
[单项选择]有如下程序段:
public class Parent
public int addValue (int a,int b)
int s;
s=a+b;
return 3;
class Child extends Parent
则下列选项中,可以正确加入类Child中且父类的方法不会被覆盖的是( )。
A. int addValue (int a,intb) //do something...
B. public void addValue() //do something...
C. public int addValue (int a,intb)throws MyException //do something...
D. public float addValue (int a,int b,float b=1.0) //do someting...
[填空题]下列是一个类的定义程序段,请补充完整。
public class My Class
int x,y;
MyClass(int i, 【11】 )
x=i;y=j;
[单项选择]下列代码的执行结果是 public class Test public int aMethod( ) static int i=0; i+ +; System.out.println(i); public static void main(String args[ ]) Test test = new Test( ); test.aMethod( );
A. 编译错误
B. 0
C. 1
D. 运行成功,但不输出
[单项选择]下列代码的执行结果是
public class Test
public int aMethod( )
static int i=0;
i++;
System.out.println(i);
public static void main(String args[])
Test test= new Test( );
test. aMethod( );
A. 编译错误
B. 0
C. 1
D. 运行成功,但不输出
[单项选择]有如下类定义:
class AA
int a;
public:
int getRef( )const return &a; //①
int getValue( )const return a; //②
void set(int n)const a=n; //③
friend void show(AA a
A. const cout<<a;
[单项选择]下列代码的执行结果是( )。
public class Test
public int aMethod( )
static int i=0;
1++;
System.out.println(i):
public static void main (String args[])
Trest test=new Test ( );
test aMethod( ):
A. 编译错误
B. 0
C. 1
D. 运行成功,但不输出
[填空题]阅读并完成程序。
public class Class27
int m,n;
public______
public______m=a;
public static void main(String args[])
Class27 t1,t2;
int j=0;
t1=new Class27( );
t2=new Class27(j);
[单项选择]有如下类定义: class AA { int a; public: int getRef( )const{ return &a; } //① int getValue( )const{ return a; } //② void set(int n)const{ a=n; } //③ friend void show(AA aa)const{ cout<<a; } //④ }; 其中的四个函数定义中正确的是( )。
A. ①
B. ②
C. ③
D. ④
[单项选择]若类A和类B的定义如下:
class A
[
int i,j;
public:
int geti( )
return i;
;
class B:public A
int k;
public:
void make( )
k=i*j;
;
则上述定义中非法的表达式是
A. k=i*j
B. int k;
C. retum i;
D. void make()
[单项选择]若类A和类B的定义如下:
class A
int i,j;
public:
void get( );
//…
;
class B:A//默认为私有派生
int k;
public:
void make( );
//…
;
void B::make( )
k=i*j;
则上述定义中, ( )是非法的表达式。
A. void get();
B. int k;
C. void make();
D. k=i*j;
[单项选择]有如下程序
public class Test
int a,b;
Test( )
a=100;
b=200;
Test(int x,int y)
a = x;
b = y;
public static void main(String args[])
Test Obj1=new Test(12,45);
System.out.println("a = "Obj1.a+" b= "+Obj1.B) ;
Test Obj1=new Test( );
System.out.println("a = "Obj1.a+" b= "+Obj1.B) ;
程序的运行结果为( )。
A. a=100 b=200
B. a=12 b=45
C. a=12 b=200
D. a=100 b=45