Java Test3
Question 1
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
Question 2
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
Question 3
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
Question 4
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
Question 5
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
Question 6
Which of the following are not methods of the java.lang.String class?
a. append
b. concat
c. delete
d. insert
e. replace
f. substring
g. valueOf
0 comments:
Post a Comment