1Which of the following fragments might cause errors? (5%)
A. String s = “Gone with the wind”;
String t = ” good “;
String k = s + t;
B. String s = “Gone with the wind”;
String t;
t = s[3] + “one”;
C. String s = “Gone with the wind”;
String standard = s.toUpperCase();
D. String s = “home directory”;
String t = s – “directory”;
2 public class Parent { (5%)
public int addValue( int a, int b) {
int s;
s = a+b;
return s;
}
}
class Child extends Parent {
}
Which methods can be added into class Child?
A. int addValue( int a, int b ){// do something…}
B. public void addValue (){// do something…}
C. public int addValue( int a ){// do something…}
D. public int addValue( int a, int b )throws MyException {//do something…}
3 Given: (5%)
Exhibit:
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 text BufferString = new StringBuffer (“java”);
stringReplace (textString);
bufferReplace (textBuffer);
System.out.printIn (textString + textBuffer);
}
}
What is the output?