更多"#include<iostream.h> class A "的相关试题:
[填空题]
[程序]
#include
#include
class B{
public:
B(char *s){name=new char[strlen(s)+1];strcpy(name,s);}
virtual void print( ){cout<<"姓名;"<
protected:
char *name;
};
class P1:public B{
public:
P1(char *s,float g):B(s){x=g;}
void print(int i)
{ cout<<"姓名:"<年薪:"<万元。 /n";}
private:
float x;
};
class P2:public B{
public:
P2(char *s,int n):B(s){ num=n;}
void print( ){cout<<"姓名;"<月工资:"<元。/n";}
private:
int num;
};
void main(void)
{
B *p;
B x("张明");
P1 y("王虎",4.2);
P2 z("李建国",5000);
p=&x;p->print( );
p=&y;p->print( );
y.print(1);
p=&z;p->print( );
}
执行以上程序后输出的第二行是() ,第四行是()。
[单项选择]下列程序的输出结果是
#include
class Myclass
public:Myclass(int i=0,intj=0)
x=i;
y=j;
void show( ) cout < < "x=" < < x < < " " < "y=" < < y < < end1;
void show( )const cout < < "x=" < < " " < < "y=’ < < y < < end1;
privated:
int x; int y;
;
void main( )
Myclass my1(3,4);
const my2(7,8);
my1.show( );my2.show( );
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]阅读下面程序
public class ForLoopStatement
public static void main(String[] args)
int i,j;
for(i=1;i<5;i++) //i循环
for(j=1;j<=i;j++)System.out.print(i+"*"+j+"="+i*j+" "); //j循环
System.out.println( );
程序完成后,i循环和J循环执行的次数分别是
A. 4,10
B. 8,9
C. 9,8
D. 10,10
[单项选择]请阅读下面程序
public class ExampleStringBuffer
public static void main (String[]args)
StringBuffer sb=new StringBuffer("test");
System.out.printIn("buffer="+sb);
System, out.printIn("length="+sb.length( ));
程序运行结果中在“length=”后输出的值是______。
A. 10
B. 4
C. 20
D. 30
[单项选择]下面程序运行后,输出结果为( )
public class Class07
Class07( )
System. out. println("0param");
Class07(int n)
System. out. println(n+"param");
public static void main(String[] args)
Class07 x=new Class07(100);
A. 出错
B. 0param
C. 100param
D. 程序不错,但没有信息输出
[单项选择]下列程序的输出结果是 #include class Myclass {
public:Myclass(int i=0,intj=0) { x=i;
y=j; } void show( ) { cout < < "x=" < < x
< < " " < "y=" < < y < < end1;} void show( )const { cout < < "x=" <
< " " < < "y=’ < < y < < end1;} privated:
int x; int y; }; void main(
) { Myclass my1(3,4); const my2(7,8);
my1.show( );my2.show( );}
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]阅读下面程序
public class Increment
public static void main (String args[]
int c;
c=5;
System.out.printIn(c);
System.out.printIn(c++)j
System.out.printIn (c);
程序运行结果是______。
A. 5
B. 5
C. 6
D. 6
[单项选择]阅读下面程序
public class ConcatTest
public static void main(String[] args)
String str1="abc";
String str2="ABC":
String str3=str1.concat(str2);
System.out.println(str3);
程序运行的结果是
A. abc
B. ABC
C. abcABC
D. ABCabc
[简答题]阅读下列程序
public class VariableUse
public static void main(String[]args)
int a;
if(a==8)
int b=9;
System.out.println(’a=’+a);
Systern.out.println(’b=’+b);
System.out.println(’a=’+a);
System.out.println(’b=’+b);
该程序在编译时的结果是( )。
[填空题]public class Test
public static void main(String[ ] args)
String name[ ]=new String[5];
for(int i=0; i<args. length; ++i) name[i] = args[i];
System. out. println(name[2]);
命令行中的输入为:java Test a b
程序的输出是 【11】 。
[单项选择]阅读下列代码
public class Test
public static void main(String args[])
String s = "Test";
switch (s)
case "Java": System. out. print("Java"); break;
case "Language": System. out. print("Language"); break;
case "Test": System. out. print("Test"); break;
其运行结果是( )。
A. Java
B. Language
C. Test
D. 编译出错
[单项选择]阅读下面程序:
public class ThreadTest
public static void main(String args[]) throws Exception
int i=0;
Hello t=new Hello( );
______;
While(true)
System.out.println("Good Morning"+i++);
if(i==2&&t.isAlive( ))
System.out.println("Main waiting for Hello!");
t.join( ); //等待t运行结束
If(i==5)break:
class Hello extends Thread
int i;
public void run( )
while(true)
System.out.println("Hello"+i++):
If(i==5)break;
为使该程序正确执行,下画线处的语句应是
A. sleep()
B. yield()
C. interrupt()
D. start()
[单项选择]请阅读下面程序
public class ForLoopStatement
public static void main (String[] args)
int i;j;
for(i=1;i<5;j++)//i循环
for(j=1;j<=i;j++)//j循环
System.out.print(i+"*"+j+"="+i*j+" ");
System.out.printIn( );
程序完成后,i循环和j循环执行的次数分别是______。
A. 4,10
B. 8,9
C. 9,8
D. 10, 10
[单项选择]阅读下面代码
public class Arrays
public static void main(String[] args)
int[] a=new int[5];
for(int i=0;i<a.length;i=i+1)a[i]=10+i;
for(int i=0;i<a.length;i=i+1)System.out.println(a[i]);
String[] s="Frank","Bob","Jim";
for(int i=0;i<s.length;i=i+1)System.out.println(s[i]);
s[2]="Mike";
System.out.println(s[2]);
代码运行正确的结果是
A. 10
B. 11
C. 10
D. 11
[单项选择]阅读下面代码
public class Jixiangwu
public static void main(String[] args)
String[] stars="贝贝","晶晶","欢欢","迎迎","妮妮";
System.out.println("你抽取的奥运吉祥物是"+
"“"+stars[(int)(stars. ______ *Math.random( ))]+"”"+"!");
为保证程序能正确执行,程序中下画线处应填写的是
A. long
B. width
C. wide
D. length
[单项选择]阅读下列代码
public class Arrays
public static void main(String[]args)
int[]a=new int[5];
for(int i=0;i<a. length; i=i+1)
a[i]=10+i;
for(int i=0; i<a. length; i=i+1)
System. out. println(a[i]);
String[]s="Frank","Bob","Jim";
for(int i=0; i<s. length; i=i+1)
System. out. println(s[i]);
S[2]="Mike";
System. out. println(s[2]);
代码运行结果正确的是
A. 10
B. 11
C. 10
D. 11
[单项选择]阅读下面程序 public class Increment { public static void main( String args[] ){ int c; c=5; System.out.println( c ); System.out.println( c++ ); System.out.println( c ); } )程序运行结果是( )。
A. 5 6 6
B. 5 5 6
C. 6 7 7
D. 6 6 6
[单项选择]阅读下面程序 public class VariableUse { public static void main(String[] arqs) { int a; if(a==8) { int b=9; System.out.println("a="+a); System.out.println("b="+b); } System.out.println("a="+a); System.out.println("b="+b): } } 该程序在编译时的结果是
A. 变量a未赋值
B. 第二个System.out.println("b="+b);语句中,变量b作用域有错
C. 第二个System.out.println("a="+a);语句中,变量a作用域有错
D. 第一个System.out.println("b="+b);语句中,变量b作用域有错
[单项选择]请阅读下面程序
public class ThreadTest
public static vodi main(Sting args[])
Thread t1=new Thread(new Hello( ));
Thread t2=new Thread(new Hello( ));
t1.start( );
t2.start( );
class Hello implements Runnable
int i;
public void run( )
while (true)
System.out.printIn("Hello"+i++);
if(i==5) break;
该程序创建线程使用的方法是______。
A. 继承Thread类
B. 实现Runnable接口
C. t1.start()
D. t2.start()