class SRC102 {
public static void main (String[] args) {
int i1 = Math.round(0.5f);
int i2 = Math.round(1.5d);
System.out.print(i1 + "," + i2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,1 |
| b. | Prints: 0,2 |
| c. | Prints: 1,1 |
| d. | Prints: 1,2 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class A {
public static void main (String args[]) {
byte primitiveByte = 1; // 1
Byte b1 = new Byte(primitiveByte); // 2
Byte b2 = new Byte(1); // 3
System.out.print(b1.byteValue() + b2.byteValue());
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 2 |
| b. | Prints: 11 |
| c. | Compile-time error at 1 |
| d. | Compile-time error at 2 |
| e. | Compile-time error at 3 |
| f. | Run-time error |
| g. | None of the above |
class A {
public static void main (String args[]) {
byte primitiveByte = 1;
char primitiveChar = 'b'-'a';
int primitiveInt = 1;
short primitiveShort = 1;
String s = "1";
Integer i1 = new Integer(primitiveByte);
Integer i2 = new Integer(primitiveChar);
Integer i3 = new Integer(primitiveShort);
Integer i4 = new Integer(primitiveInt);
Integer i5 = new Integer(s);
int p1 = i1.intValue() + i2.intValue() +
i3.intValue() + i4.intValue() +
i5.intValue();
System.out.print(p1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 5 |
| b. | Prints: 5.0 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class A {
public static void main (String args[]) {
byte primitiveByte = 1;
int primitiveInt = 1;
long primitiveLong = 1L;
float primitiveFloat = 1f;
String s = "1";
Long i1 = new Long(primitiveByte);
Long i2 = new Long(primitiveInt);
Long i3 = new Long(primitiveLong);
Long i4 = new Long(primitiveFloat);
Long i5 = new Long(s);
int i6 = i1.intValue() + i2.intValue() +
i3.intValue() + i4.intValue() +
i5.intValue();
System.out.print(i6);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 5 |
| b. | Prints: 5.0 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class A {
public static void main (String args[]) {
byte primitiveByte = 1;
char primitiveChar = 1;
double primitiveDouble = 1;
String s = "1";
Double d1 = new Double(primitiveByte);
Double d2 = new Double(primitiveChar);
Double d3 = new Double(primitiveDouble);
Double d4 = new Double(s);
double d5 = d1.doubleValue() + d2.doubleValue() +
d3.doubleValue() + d4.doubleValue();
System.out.print(d5);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 4 |
| b. | Prints: 4.0 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class C {
public static void main (String[] args) {
Float f1 = new Float(1.0); // 1
Float f2 = new Float("1.0"); // 2
Float f3 = new Float("1.0f"); // 3
Float f4 = new Float("1e1f"); // 4
Float f5 = new Float(".1e1d"); // 5
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at 1 |
| b. | Compile-time error at 2 |
| c. | Compile-time error at 3 |
| d. | Compile-time error at 4 |
| e. | Compile-time error at 5 |
| f. | Run-time error at 1 |
| g. | Run-time error at 2 |
| h. | Run-time error at 3 |
| i. | Run-time error at 4 |
| j. | Run-time error at 5 |
| k. | None of the above |
class A {
public static void main(String[] args) {
Boolean b1 = new Boolean(true); // 1
Boolean b2 = new Boolean(false); // 2
Boolean b3 = new Boolean(TRUE); // 3
Boolean b4 = new Boolean(FALSE); // 4
Boolean b5 = new Boolean("TrUe"); // 5
Boolean b6 = new Boolean("fAlSe"); // 6
}}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
Which of the following class instance creation expressions would generate a compile-time error?
| a. | new Short(1) |
| b. | new Short('1') |
| c. | new Short('b' - 'a') |
| d. | new Short((short)1 - (short)2) |
| e. | new Short((byte)1) |
| f. | new Short((short)1) |
class SRC103 {
public static void main (String[] args) {
int i1 = Math.round(0.5f);
int i2 = Math.round(1.5f);
System.out.print(i1 + "," + i2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,1 |
| b. | Prints: 0,2 |
| c. | Prints: 1,1 |
| d. | Prints: 1,2 |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class B {
public static void main (String args[]) {
Byte b1 = new Byte(1); // 1
Byte b2 = new Byte('2'); // 2
Byte b3 = new Byte("3"); // 3
byte i1 = b1.byteValue()+b2.byteValue()+b3.byteValue(); // 4
System.out.print(i1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 6 |
| b. | Compile-time error at 1 |
| c. | Compile-time error at 2 |
| d. | Compile-time error at 3 |
| e. | Compile-time error at 4 |
| f. | Run-time error |
class A {
public static void main (String args[]) {
int primitiveInt = 1;
long primitiveLong = 1L;
float primitiveFloat = 1.0f;
String s = "1";
Integer i1 = new Integer(primitiveInt);
Integer i2 = new Integer(primitiveLong);
Integer i3 = new Integer(primitiveFloat);
Integer i4 = new Integer(s);
int i5 = i1.intValue() + i2.intValue() +
i3.intValue() + i4.intValue();
System.out.print(i5);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 4 |
| b. | Prints: 4.0 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class B {
public static void main (String args[]) {
Long i1 = new Long(1);
Long i2 = new Long(i1);
System.out.print((i1==i2) + "," + i1.equals(i2));
}}
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 A {
public static void main (String args[]) {
Double d1 = new Double(1.0);
Double d2 = new Double(d1);
System.out.print(d1.equals(d2));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false |
| b. | Prints: true |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class F {
public static void main (String[] args) {
Float f1 = new Float('B' - 'A'); // 1
Float f2 = new Float(010); // 2
Float f3 = new Float(0x10); // 3
Float f4 = new Float(.1e1); // 4
Float f5 = new Float(1.0); // 5
Float f6 = new Float(1.0d); // 6
System.out.print(f1+","+f2+","+f3+","+f4+","+f5+","+f6);
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at 1 |
| b. | Compile-time error at 2 |
| c. | Compile-time error at 3 |
| d. | Compile-time error at 4 |
| e. | Compile-time error at 5 |
| f. | Compile-time error at 6 |
| g. | Run-time error at 1 |
| h. | Run-time error at 2 |
| i. | Run-time error at 3 |
| j. | Run-time error at 4 |
| k. | Run-time error at 5 |
| l. | Run-time error at 6 |
| m. | Prints: 1.0,10.0,10.0,1.0,1.0,1.0 |
| n. | Prints: 1.0,8.0,16.0,1.0,1.0,1.0 |
| o. | None of the above |
class B {
public static void main(String[] args) {
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
Boolean b3 = new Boolean("TrUe");
Boolean b4 = new Boolean("tRuE");
System.out.print((b1==b2) + ",");
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");
System.out.println(b3.equals(b4));
}}
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. | None of the above |
Which of the following class instance creation expressions would generate a compile-time error?
| a. | new Short("1") |
| b. | new Short("-1") |
| c. | new Short("1.0") |
| d. | new Short("0x1") |
| e. | new Short("011") |
| f. | None of the above |
class MWC101 {
public static void main(String[] args) {
String s1 = "A", s2 = "a", s3 = "b";
s1.toLowerCase(); s3.replace('b','a');
System.out.print((s1.equals(s2)) + "," + (s2.equals(s3)));
}}
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 MWC200 {
public static void main (String[] args) {
String s1 = "ABC";
StringBuffer s2 = new StringBuffer(s1);
System.out.print(s2.equals(s1) + "," + s1.equals(s2));
}}
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 MWC102 {
public static void main (String[] args) {
String s1 = "ABCDE";
System.out.print(s1.substring(1,2)+s1.substring(3));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AABC |
| b. | Prints: ACDE |
| c. | Prints: ABABC |
| d. | Prints: ABCDE |
| e. | Prints: BABCD |
| f. | Prints: BDE |
| g. | Prints: BCABCD |
| h. | Prints: BCDE |
| i. | Compile-time error |
| j. | Run-time error |
| k. | None of the above |
class MWC201 {
public static void main (String[] args) {
String s1 = new String("ABC"), s2 = new String("ABC");
StringBuffer sb1 = new StringBuffer(s1);
StringBuffer sb2 = new StringBuffer(s2);
System.out.print(s1.equals(s2) + "," + sb1.equals(sb2));
}}
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 |