Java Mock Test 3

Java Mock Test 3

Java Mock Test 3, 10 QUESTIONS

published on June 28, 2009125 responses 1 5.0★ / 5

What will be displayed after you try to compile and execute the following code?
------
int i = 10;
if(i) {
System.out.println("A");
} else {
System.out.println("B");
}

A
B
Compilation Error
Nothing will be displayed

How do you write an infinite loop?

Select the three correct answers
for(;;) {

}
while (true) {

}
do {

} while (true);

Which of the following variables are defined correctly?

Select the three correct answers
String $;
String _;
String 12x;
String x12;
String s#;
String h@ppy;
String myString#2;

How many primitive data types are in Java?

5
6
7
8
9
10
12

Which will be the value of variable y after you compile and execute the following block of code?
------
public class MyClass {

private int x =10;

public static void main(String[] args) {

int y = x++%5;
}

0
2
Compilation Error
Runtime Error

What will be displayed after you try to compile and execute the following code?
------
public static void main(String[] args) {
final String s = "A";
s.concat("B");
System.out.println(s);
}

Compilation Error
Runtime Error
A
AB
B

How many Constructors has the Character object?

1
2
3
4

Which of the following statements are true about Math.random() function

It generates an int value bigger or equal to 1 and less than 10.
It generates an int value bigger or equal to 1 and less than 100
It generates a float value bigger or equal to 0.0 and less than 1.0
None of these

What will be displayed after you try to compile and execute the following code?
------
double x = -34.45;

System.out.println(Math.floor(x));
System.out.println(Math.ceil(x));
System.out.println(Math.abs(x));

35.0
34.0
34.0
-34.0
-35.0
34.0
-35.0
-34.0
34.45
-34.0
-34.0
34.45

Is the String object immutable?

Yes
No
Depends on JRE version