A、(1)和(2)删掉一个,错误解决
B、(3)删掉,错误解决
C、没问题
第1题:
下列程序中,要求计算1+2+3+…+100的值,并显示计算结果。请将程序补充完整。
程序运行结果如下:
5050
public class ex6_1{
public static void main(Stringr)args){
ex6_1 obj6_1:new ex6_1();
obj6_1.method6_1();
}
public void method6_1(){
int sum;
___________;
for(int i=1;i<=100;i++){
___________;
}
___________;
}
}
第2题:
下列程序中,给出两个整数2和3,分别求2除以3和2乘以3的结果,要求调用类ex19_1的方法method()来输出相应的结果,请将程序补充完整。程序运行结果如下。
0.6666666666666666
6
源程序文件代码清单如下:
public class exl9 1
{
public static void main(String args[])
{
int n1=2,n2=3;
ex19_1 obj19_1=new ex19_1();
obj19_1.
}
public void method(int x,int y)
{
System.out.println(______);
System.out.println(______);
}
}
第3题:
阅读下列代码段,选出该代码段的正确的文件名( )。 class A { void method () { System.out.println ("methodl in class A"); } } public class B { void method2 () { System.out.println("method2 in class B"); } public static void main (String args[]) { System.out.println ("main () in class B"); } }
A.A.java
B.A.class
C.B.class
D.B.java
第4题:
阅读下列代码段,选出该代码段的正确的文件名 ( )class A{ void methodl(){ System.out.println("methodl in class A"); }}public class B{ void method2(){ System.out.println("method2 in class B"); } public static void main(String args[]){ System.out.println("main()in class B"); }}
A.A.java
B.A.class
C.B.class
D.B.java
第5题:
下列程序中,给出两个整数2和3,分别求2除以3和2乘以3的结果,要求调用类ex1_1的方法method()来输出相应的结果,请将程序补充完整。程序运行结果如下:
0.6666666666666666
6
public class ex1_1{
public static void main(String[]args) {
int n1=2,n2=3;
ex1_1 obj1_1=new ex1_1();
obj1_1. ______;
}
public void method(int x,int y){
System.out.println(______);
System.out.println(______);
}
}
第6题:
下列程序的运行结果为______。 class A { int b=0; } public class ex35 public static void main(String args[]) { ex35 t=new ex35(); t.method(); } void method() { A A1=new A(); A A2=new A(); A1,b=A2.b=12; boolean b=A1.equals(A2); Syatem.out.println(b); } }
A.true
B.false
C.0
D.1
第7题:
设有程序如下: abstract class absclass { abstract void method1(); } class conclass extends absclass { public void method1() { System.out.println("子类");} } public class mainclass { public static void main(String args[]) { absclass ac1=new absclass(); //语句1 absclass ac2=new conclass(); //语句2 ac2.method1(); //语句3 } } 则main()方法中的第一条语句(即语句1)可以顺利通过编译。()
此题为判断题(对,错)。
第8题:
A programmer needs to create a logging method that can accept an arbitrary number of arguments.Forexample,it may be called in these ways: logIt("log message 1"); logIt("log message 2”,”log message 3"); logIt("log message 4","log message 5","log message 6"); Which declaration satisfies this requirement()?
第9题:
A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt(”log message 1 “); logIt(”log message2”,”log message3”); logIt(”log message4”, “log message5”, “log message6); Which declaration satisfies this requirement?()
第10题:
public class TestFive { private int x; public void foo() { int current = x; x = current + 1; } public void go() { for(int i=0;i<5;i++) { new Thread() { public void run() { foo(); System.out.print(x + “, “); } }.start(); }}} Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()
第11题:
on line 2
on line 3
on line 6
on line 7
第12题:
public void logIt(String * msgs)
public void logIt(String [] msgs)
public void logIt(String... msgs)
public void logIt(String msg1, String msg2, String msg3)
第13题:
A programmer needs to create a logging method that can accept an arbitrary number of arguments.Forexample,it may be called in these ways:logIt("log message 1");logIt("log message 2”,”log message 3");logIt("log message 4","log message 5","log message 6");Which declaration satisfies this requirement()?
A.public void logIt(String*msgs)
B.public void logIt(String[]msgs)
C.public void logIt(String...msgs)
D.public voidl ogIt(Stringmsg1,Stringmsg2,Stringmsg3)
第14题:
类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}
A.public float Method(float a,float b,float c){}
B.public float Method(float c,float d){}
C.public int Method(int a,int b){}
D.private float Method(int a,int b,int c){}
第15题:
2下列程序的执行结果是( )。 public class ex68 { public static void main(String[] args) { ex68 bj=new ex680; int s=0; for(int i=1; i<=4; i++){ s+=obj.method(i); } System.out.println(s); } public int method(int n) { if(n==1) return 1; else tatum n * method(n-1); } }
A.3
B.9
C.33
D.153
第16题:
下列程序的执行结果是 ( ) public class ex68{ public static void main(String[]args){ ex68 obj=new ex68(); int s=0; for(int i=1;i<=4;i++){ s+=obj.method(i); } System.out.println(s); } public int method(int n){ if(n==1) return 1; else return n*method(n-1); } }
A.3
B.9
C.33
D.153
第17题:
类Test定义如下,将下列哪个方法插入③行处是不合法的( )?
① public class Test{
② public float Method(float a,float B) { }
③ ______
④ }
A.public float Method(float a,float b,float C) { }
B.public float Method(float c,float d){ }
C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }
D.private float Method(int a,int b,int C) { }
第18题:
以下程序的输出结果为:
public class test {
public static void main(String args[]) {
int s=0;
for (int k=0;k<=10;k++)
s+=method(2,k)-1;
System.out.println(s);
}
public static int method(int n,int m) {
if (m==0)
return 1;
else
return n*method(n,m-1、;
}
}
A. 2048
B. 1024
C. 2036
D.2000
第19题:
第20题:
对于下列代码: 1) class Person { 2} public void printValue(int i, int j) {//... } 3} public void printValue(int i){//... } 4} } 5) public class Teacher extends Person { 6} public void printValue( ) {//... } 7} public void printValue(int i) {//...} 8} public static void main(String args[]){ 9} Person t = new Teacher( ); 10} t.printValue(10); 11} } 第10行语句将调用哪行语句?()
第21题:
1) class Person { 2) public void printValue(int i, int j) {/*…*/ } 3) public void printValue(int i){/*...*/ } 4) } 5) public class Teacher extends Person { 6) public void printValue() {/*...*/ } 7) public void printValue(int i) {/*...*/} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) } 12) } Which method will the statement on line 10 call? ()
第22题:
on line 2
on line 3
on line 6
on line 7
第23题:
Move the line 12 print statement into the foo() method.
Change line 7 to public synchronized void go() {.
Change the variable declaration on line 3 to private volatile int x;.
Wrap the code inside the foo() method with a synchronized( this ) block.
Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.