Java From Beginner To Advanced

0% completed

Previous
Next
Quiz
Question 1
What is the output of the following nested if...else statement?
int x = 15;
if (x > 10) {
    if (x < 20) {
        System.out.println("x is between 10 and 20");
    } else {
        System.out.println("x is 20 or more");
    }
} else {
    System.out.println("x is 10 or less");
}
A
x is between 10 and 20
B
x is 20 or more
C
x is 10 or less
D
No output
Question 2
What will be the output of the following Java code using the switch statement?
int number = 2;
switch (number) {
    case 1:
        System.out.println("One");
    case 2:
        System.out.println("Two");
    case 3:
        System.out.println("Three");
        break;
    default:
        System.out.println("Default");
}
A
Two
B
Two Three
C
Two Three Default
D
Two Default
Question 3
What does the following ternary operator expression evaluate to?
int a = 8;
int b = 12;
int max = (a > b) ? a : b;
A
8
B
20
C
12
D
Compilation Error

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next