Question 1 of 10
What text does this Java code display?
System.out.print("ket" + "ch");
- A. ket ch
- B. ketch
- C. chket
- D. ket+ch
What text does this Java code display?
System.out.print("ket" + "ch");
String objects are immutable. What text does this caller display?
String a = "fir";
String b = a + "n";
System.out.print(a + "," + b);
What text does this Java code display?
System.out.print("n" + 3 + 1);
SlipMark.toString is supplied as shown. What text does this caller display?
class SlipMark {
private int number;
public SlipMark(int n) {
number = n;
}
public String toString() {
return "slip-" + number;
}
}
SlipMark m = new SlipMark(14);
System.out.print("at " + m);
What text does this Java code display?
String w = "willow";
System.out.print(w.length());
What text does this Java code display?
String w = "harbor";
System.out.print(w.substring(2));
What text does this Java code display? Brackets mark the result.
String w = "harbor";
System.out.print("[" + w.substring(6) + "]");
What text does this Java code display?
String w = "cacao";
System.out.print(w.indexOf("ao"));
What text does this Java code display?
String p = new String("fjord");
String q = "fjord";
System.out.print(p.equals(q));
The table shows compareTo calls. Which row is correct? Do not assume a specific nonzero magnitude.
| Expression | Sign of result |
|---|---|
| "glen".compareTo("fjord") | positive |
| "ketch".compareTo("ketch") | zero |
| "oak".compareTo("oaken") | negative |