© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Flow Control and Exception Handling ▼

Java Interview Questions On Flow Control and Exception Handling

29. What is the result when you compile and run the following code?
int a = 0, b = 6, c = 10;
if (a > 5) {
if ( b < 5 ) {
System.out.println("Frist");
}s
else {
System.out.println("Second");
}
}
else if (c > 5) {
System.out.println("Third");
}
else {
System.out.println("Fourth");
}

[a] Nothing is printed
[b] First is printed
[c] Second is printed
[d] Third is printed
[e] Fourth is printed

Answer

[d] Third is printed

30. How can you change the break statement below so that it breaks out of the inner and middle loops
and continues with the next iteration of the outer loop?
outer: for ( int x =0; x < 3; x++ ) {
middle: for ( int y=0; y < 3; y++ ) {
if ( y == 1)
break;
}
}
}

[a] break inner:
[b] break middle:
[c] break outer:
[d] continue
[e] continue middle

Answer
[b] break middle;

31. What is the result of attempting to compile and run the following class?
public class Test {
public static void main(String args[]) {
int[] Myarray = new int[3];
for ( int i = 0 ; i < Myarray.length; i++ ) {
System.out.println(i);
}
}
}
[a] 0
[b] 1
[c] 2
[d] 3
[e] The program does not compile.

Answer
[a] 0
[b] 1
[c] 2

Previous Next
1 2 3 4 5 6 7 8 9
SLogix Student Projects
bottom