Javaˮƽ²âÊÔC¾í
Question No: 1
Given:
public class TestAmigo {
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;
}
}
What is the result?
A. The code compiles and prints ¡°A,B¡±.
B. The code compiles and prints ¡°A,A¡±.
C. The code compiles and prints ¡°B,B¡±.
D. The code compiles and prints ¡°AB,B¡±.
E. The code compiles and prints ¡°AB,AB¡±.
F. The code does not compile because ¡°+¡± cannot be overloaded for StringBuffer
Question No: 2
Given:
public class TestAmigo {
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);
}
}
What is the output?
£Ájavajava¡¡£Âiavajava¡¡£ÃiavaJavaC¡¡£Ä javajavaC E None of these
Question No: 3
Given: