以下程序的编译和运行结果为?class test {static boolean check;public static void main(String args[]) {int i;if(check == true)i=1;elsei=2;if(i= 2、i=i+2;else i = i + 4;System.out.println(i);}}
A. 3
B. 4
C. 5
D. 6
E. 语句if(i= 2、编译出错
A. 3
B. 4
C. 5
D. 6
E. 语句if(i= 2、编译出错
A. 输出结果为 0
B. 运行出错
C. 输出结果为 null
D. 编译错误
以下的程序的调试结果为?
public class As{
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(String argv[]){
As a = new As();
A.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b);
}
}
A.输出0 和false
B. 输出0 和true
C. 编译错误,b 未初始化
D. 编译错误, z 必须赋字符值
A.编译失败
B.编译通过,没有结果输出
C.输出:除法正常运行
D.输出:除数不能为0
A.equals(aa));}}class AB{ int x = 100; }
B.true
C.false
D.编译错误
E.100
A. 3
B. 4
C.5
D.6
E.7
class A
{
int a;
A(int b)
{a=b;}
void show()
{System.out.println(“a=”+a);}
}
public class Class1
{
public static void main (String args[])
{
A bj=new A(12345);
boolean b=false;
char ch=97;
obj.show();
System.out.println(“b=”+b+”/tch=”+ch);
}
}
给出下面代码,关于该程序以下哪个说法是正确的()?public class Person static in tarr=new int5;public static void main(Stringa)System.out.println(arr0);
A.编译时将产生错误
B.编译时正确,运行时将产生错误
C.输出零
D.输出空
下面程序的运行结果为()。 #include<iostream.h> class A { int num public: A(int i){num=i;} A(A&a){Bum=a.num++;} void print(){cout<<Bum;} }; void main() { A a(1),b(a); A. print(); B.print(); }
A.11
B.12
C.21
D.22
阅读下列程序,请写出程序的运行结果。
import java.applet.*;
import java.awt.*;
public class C extends Applet implements Runnable
{
Thread redBall,blueBall;
Graphics redPen,bluePen;
int blueSeta=0,redSeta=0;
public void init()
{
setSize(250,200);
redBall=new Thread(this);
blueBall=new Thread(this);
redPen=getGraphics();
bluePen=getGraphics();
redPen.setColor(Color.red);
bluePen.setColor(Color.blue);
setBackground(Color.gray);
}
public void start()
{
redBall.start();
blueBall.start();
}
public void run()
{
intx,y;
while(true)
{
if(Thread.currentThread()==redBall)
{//以下代码为顺时针画圆
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.gray);
redPen.fillOval(100+x,100+y,10,10);
redSeta+=3;
if(redSeta>=360)redSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.red);
redPen.fillOval(100+x,100+y,10,10);
try{redBall.sleep(20);}
catch(InterruptedException e){}
}
elseif(Thread.currentThread()==blueBall)
{//以下代码为顺时针画圆
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.gray);
bluePen.fillOval(150+x,100+y,10,10);
blueSeta-=3;
if(blueSeta<=-360)blueSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.blue);
bluePen.fillOval(150+x,100+y,10;10);
try{blueBall.sleepp(40);}
catch(InterruptedException e){}
}
}
}
}
有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=&obj1; p=&obj2; p->who (); return 0; } 执行程序后的输出结果是()。
A.Base Class
B.Derivel Class
C.Derive2 Class
D.程序编译时出错