problem

5. Given:
public class Foo {
public static void main (String [] args) {
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer ("B");
operate (a,b);
System.out.println(a + "," +b);
}
static void operate(StringBuffer x, StringBuffer y) {
x.append(y);
y = x;
}
}

===================== http://www.opcol.com/

6. Given:
public class Test {
public static void stringReplace (String text) {
text = text.replace('j', 'i');
}
public static void bufferReplace (StringBuffer text) {
text = text.append ('c');
}
public static void main (String args[]) {
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}

=======================
public class Test {
public static void add3(Integer i) {
int val = i.intValue();
val += 3;
i = new Integer(val);
}
public static void main(String args[]){
Integer i = new Integer(0);
add3 (i);
System.out.println (i.intValue());
}
}
====================
18. Which three are valid declarations of a float? (Choose Three)
A. float foo = -1;
B. float foo = 1.0;
C. float foo = 42e1;
D. float foo = 2.02f;
E. float foo = 3.03d;
F. float foo = 0x0123;
========================
15. Given:
interface Foo {
int k = 0; //line 2
}
public class Test implements Foo {
public static void main(String args[]) {
int i;
Test test = new Test();
i = test.k; //8
i = Test.k; //9
i = Foo.k; //10
}
}
============================
22. Given:
public class Foo {
public static void main (String[] args) {
String s;
System.out.println (“s=” + s);
}
}
=============================
26. Given:
public class test{
public int aMethod(){
static int i=0;
i++;
return i;
}
public static void main (String args[]){
test test = new test();
test.aMethod();
int j = test.aMethod();
System.out.printIn(j);
}
}
What is the result?
A. Compilation will fail.
B. Compilation will succeed and the program will print “0”.
C. Compilation will succeed and the program will print “1”.
D. Compilation will succeed and the program will print “2”.

==========================
27. Given:
class Super {
public float getNum() {return 3.0f;}
}
public class Sub extends Super {
//line 5
)
Which method, placed at line 5, will cause a compiler error?
A. public float getNum() { return 4.0f; }
B. public void getNum() {}
C. public void getNum(double d) {}
D. public double getNum(float d) {retrun 4.0f; }
==========================
29. Given:
byte [] array1, array2[];
byte array3 [][];
byte[][] array4;
If each array has been initialized, which statement will cause a compiler error?
A. array2 = array1;
B. array2 = array3;
C. array2 = array4;
D. both A and B
E. both A and C
F. both B and C
=========================
52. Given:
public class Test {
public static String output = "";
public static void foo(int i) {
try {
if(i==1) {
throw new Exception ();
}
output += "1";
} catch(Exception e) {
output += “2”;
return;
} finally (
output += “3”;
}
output += “4”;
}
public static void main (String args[]) (
foo(0);
foo(1);
//line 24
}
)
=========================
53. Given:
public class Foo implements Runnable { //line 1
public void run (Thread t) { //line 2
System.out.println("Running.");
}
public static void main (String[] args) {
new Thread(new Foo()).start();
}
}
========================
59. Given:
public class X implements Runnable {
private int x;
private int y;
public static void main(String[] args) {
X that = new X();
(new Thread(that)).start(); //line 7
(new Thread(that)).start(); //line 8
}
public synchronized void run{} { //line 11
for (;;) {
x++;
y++;
System.out.println(“x = “ + x + “, y = “ + y);
}
}
}
===============================
61. Given:
public class SyncTest{
public static void main(String[] args) {
final StringBuffer s1= new StringBuffer();
final StringBuffer s2= new StringBuffer();
new Thread () {
public void run() {
synchronized(s1) {
s2.append(“A”);
synchronized(s2) {
s2.append(“B”);
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread() {
public void run() {
synchronized(s2) {
s2.append(“C”);
synchronized(s1)
s1.append(“D”);
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
Which two statements are true? (Choose Two)
A. The program prints “ABBCAD”
B. The program prints “CDDACB”
C. The program prints “ADCBADBC”
D. The output is a non-deterministic point because of a
possible deadlock condition
E. The output is dependent on the threading model of the
system the program is running on.
============================
68. Given:
class A {
public int getNumber(int a) {
return a + 1;
}
}
class B extends A {
public int getNumber(int a) {
return a + 2; //line 8
}
public static void main (String args[]) {
A a = new B(); //line 13
System.out.println(a.getNumber(0)); //line 14
}
}
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 13 causes compilation to fail.
E. An error at line 14 causes compilation to fail.
Answer: B
========================
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值