Java Programming Questions and Answers
Showing 1 -
4 of
4 questions
1
1.What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j > i; j--)
assert i!=j {System.out.println(i); }
a
The number 1 gets printed with AssertionError
b
The number 1 gets printed with AssertionError
c
The class compiles and runs, but does not print anything
d
The program generates a compilation error
2
What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;
a
The class compiles and runs, but does not print anything
b
The number 1 gets printed with AssertionError
c
The number 2 gets printed with AssertionError
d
The number 3 gets printed with AssertionError
3
- What happens when the following code is compiled and run. Select the one correct answer.
for(int i = 1; i < 4; i++)
for(int j = 1; j < 4; j++)
if(i < j)
assert i!=j : i;
a
The class compiles and runs, but does not print anything
b
The number 1 gets printed with AssertionError
c
The number 2 gets printed with AssertionError
d
The number 3 gets printed with AssertionError
4
Which of the following statement is true about the assert statement. Select the one correct answer
a
If a Java class contains assert statements, then it must be compiled with -1.4 option
b
When a program having assertions is run, -assertion option must be specified, otherwise the assertions get ignored
c
A possible syntax of assert statement is
assert logical_expression
If logical_expression evaluates to true, the program generates an AssertionError
d
The program terminates on its first AssertionError