Which of these methods modify the contents of the String instance on which it is invoked?
| a. | append |
| b. | concat |
| c. | delete |
| d. | insert |
| e. | replace |
| f. | substring |
| g. | valueOf |
| h. | None of the above. |
class SRC106 {
public static void main(String[] args) {
double d1 = Math.floor(0.5);
double d2 = Math.floor(1.5);
System.out.print(d1 + "," + d2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0.0,1.0 |
| b. | Prints: 0.0,2.0 |
| c. | Prints: 1.0,1.0 |
| d. | Prints: 1.0,2.0 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class MWC204 {
static void m1(StringBuffer s1) {
s1 = s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1.append("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABAA |
| c. | Prints: ABACA |
| d. | Prints: ABABAB |
| e. | Prints: ABABCAB |
| f. | Prints: ABABCABC |
| g. | Prints: ABCABCABC |
| h. | Compile-time error |
| i. | Run-time error |
| j. | None of the above |
class E {
public static void main (String[] args) {
Byte b1 = new Byte("1"), b2 = new Byte("1");
int a = b1.hashCode(), b = b2.hashCode();
System.out.print((b1.equals(b2))+","+(a==b));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class E {
static String m(int i) {return "int primitive";}
static String m(Integer i) {return "Integer instance";}
static String m(double i) {return "double primitive";}
static String m(Double i) {return "Double instance";}
static String m(String i) {return "String instance";}
public static void main (String[] args) {
System.out.print(m(Integer.parseInt("1")));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: int primitive |
| b. | Prints: double primitive |
| c. | Prints: Double instance |
| d. | Prints: String instance |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class F {
static String m(long i) {return "long";}
static String m(Long i) {return "Long";}
static String m(double i) {return "double";}
static String m(Double i) {return "Double";}
static String m(String i) {return "String";}
public static void main (String[] args) {
System.out.print(m(Long.parseLong("1L")));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: long |
| b. | Prints: Long |
| c. | Prints: double |
| d. | Prints: Double |
| e. | Prints: String |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
Which of the following methods are static members of the java.lang.Double class?
| a. | doubleValue |
| b. | floatValue |
| c. | intValue |
| d. | longValue |
| e. | parseDouble |
| f. | toString(double) |
| g. | valueOf |
class E {
static String m(float f) {return "f";}
static String m(Float f) {return "F";}
public static void main (String[] args) {
System.out.print(m(Float.parseFloat("1")));
System.out.print(m(Float.floatValue()));
System.out.print(m(Float.valueOf("1")));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: fff |
| b. | Prints: ffF |
| c. | Prints: fFf |
| d. | Prints: fFF |
| e. | Prints: Fff |
| f. | Prints: FfF |
| g. | Prints: FFf |
| h. | Prints: FFF |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
class D {
public static void main (String[] args) {
Boolean b1 = Boolean.valueOf("trUE"); // 1
Boolean b2 = Boolean.valueOf("Even more true"); // 2
Boolean b3 = Boolean.valueOf(null); // 3
System.out.print((b1==b2) + ",");
System.out.print((b2==b3) + ",");
System.out.println(b3==b1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
class E {
static String m(short s) {return "p";}
static String m(Short s) {return "S";}
public static void main (String[] args) {
Short s1 = new Short("1");
System.out.print(m(s1.shortValue())+",");
System.out.print(m(Short.parseShort("1"))+",");
System.out.print(m(Short.valueOf("1")));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: p,p,p |
| b. | Prints: p,p,S |
| c. | Prints: p,S,p |
| d. | Prints: p,S,S |
| e. | Prints: S,p,p |
| f. | Prints: S,p,S |
| g. | Prints: S,S,p |
| h. | Prints: S,S,S |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
Which of these methods is a static member of the java.lang.String class?
| a. | append |
| b. | concat |
| c. | delete |
| d. | insert |
| e. | replace |
| f. | substring |
| g. | valueOf |
| h. | None of the above. |
class SRC107 {
public static void main (String[] args) {
int a = -1; long b = -2;
float c = -3.0f; double d = -4.0;
a = Math.abs(a); b = Math.abs(b);
c = Math.abs(c); d = Math.abs(d);
System.out.print(a+b+c+d);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 10.0 |
| b. | Compile-time error |
| c. | Run-time error |
| d. | None of the above |
class MWC205 {
static void m1(StringBuffer s1) {
s1.append("B"); System.out.print(s1);
}
static void m2(StringBuffer s1) {
s1 = new StringBuffer("C"); System.out.print(s1);
}
public static void main(String[] s) {
StringBuffer s1 = new StringBuffer("A");
m1(s1); m2(s1);
System.out.print(s1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABCA |
| c. | Prints: ABCAB |
| d. | Prints: ABCABC |
| e. | Prints: ABCAC |
| f. | Prints: ABABCABC |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class F {
public static void main (String[] args) {
System.out.print(Byte.MIN_VALUE+","+Byte.MAX_VALUE);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -128,127 |
| b. | Prints: -127,128 |
| c. | Prints: 0,255 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class D {
public static void main (String args[]) {
boolean b1 = Integer.MIN_VALUE == 0x80000000;
boolean b2 = Integer.MAX_VALUE == 0x7FFFFFFF;
System.out.print(b1 + "," + b2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class G {
public static void main (String[] args) {
Long l1 = new Long("1"), l2 = new Long("1");
int h1 = l1.hashCode(), h2 = l2.hashCode();
StringBuffer s1 = new StringBuffer("1");
StringBuffer s2 = new StringBuffer("1");
int h3 = s1.hashCode(), h4 = s2.hashCode();
System.out.print((l1.equals(l2) & (h1==h2)) + ",");
System.out.print(s1.equals(s2) | (h3==h4));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
Which methods of the java.lang.Double class return a primitive value?
| a. | doubleValue |
| b. | floatValue |
| c. | intValue |
| d. | longValue |
| e. | parseDouble |
| f. | toString(double) |
| g. | valueOf |
class F {
static String m(float f) {return "f";}
static String m(Float f) {return "F";}
public static void main (String[] args) {
Float f1 = new Float(1);
System.out.print(m(f1.parseFloat("1")));
System.out.print(m(f1.floatValue()));
System.out.print(m(f1.valueOf("1")));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: fff |
| b. | Prints: ffF |
| c. | Prints: fFf |
| d. | Prints: fFF |
| e. | Prints: Fff |
| f. | Prints: FfF |
| g. | Prints: FFf |
| h. | Prints: FFF |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
class E {
static String m1(boolean b) {return "b";}
static String m1(Boolean b) {return "B";}
public static void main(String[] args) {
Boolean b1 = new Boolean(true);
System.out.print(m1(Boolean.valueOf(null)));
System.out.print(m1(b1.booleanValue()));
System.out.println(m1(Boolean.TRUE));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: bbb |
| b. | Prints: bbB |
| c. | Prints: bBb |
| d. | Prints: bBB |
| e. | Prints: Bbb |
| f. | Prints: BbB |
| g. | Prints: BBb |
| h. | Prints: BBB |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
class MWC106 {
static void m1(String s) {
s = s.trim(); s = s.concat("D");
}
public static void main(String[] s) {
String s1 = "A", s2 = " B ", s3 = "C";
m1(s2);
System.out.print(s1 + s2 + s3);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: ABC |
| b. | Prints: A B C |
| c. | Prints: ABCD |
| d. | Prints: ABDC |
| e. | Prints: A B CD |
| f. | Prints: A B DC |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |