DATAFLOW CONTROL

1) Which of the following statements are true about the new enhanced for loop?

1.The enhanced for loop eliminates the need for Iterator objects.
2.The enhanced for loop simplifies the process of iterating over a collection of elements
3.The introduction of enhanced for loop will bring performance bottle-necks in an Application
4.It is not possible to mix the older for loops as well as enhanced for loop in java source code of version 5.0
Answer 1: 1,2
The program recursively traverses over the directories and the files. Hence answer 1 holds good.

2) What is the output for the below code ?
public class Test {
 public static void main(String[] args) {
    char c = 'a';
 
   switch(c){
       case 65:
                System.out.println("one");break;
       case 'a':
                System.out.println("two");break;
       case 3:
                System.out.println("three");
  }
  
  }
 

}

A)one two three
B)one
C)two
D)Compile error - char can't be in switch statement.

Answer 2: C
Compile properly and print two.

3) What is the output for the below code ?
public class Test{

public static void main(String[] args) {
  int i1=1;
 switch(i1){
     case 1:
              System.out.println("one");
     case 2:
              System.out.println("two");
     case 3:
              System.out.println("three");
}
}
}

options
A)one two three
B)one
C)one two
D)Compile error.

Answer 3: A
There is no break statement in case 1 so it causes the below case statements to execute regardless of their values.


4) What is the output for the below code ?

class C{
 public static void main(String a[])      {
  int i1=9;
  int i2;
    if(i1>3) {         
        i2=8;
     }
   System.out.println(i2);
}}


A)compile time error
B)Runtim error
C)prints 8
D)prints 0
E)None of the above


Answer 4: A
since variable i1 is not final the value is not known at compiletime itself.so generate compile time error

5) What is the output for the below code ?
class c1
{
static{
System.out.println("static");
}
public static void main(String a[])
{
System.out.println("main");
}
}
1)prints static main
2)prints main
3)prints main static
4)compiletime error
5)none of the above

Ans: 1

6) What is the output for the below code ?
interface I {           //1
  public class Inner {   ///2
          
          Inner ( ) {
                  System .out . println ( "Inner Created" ) ;
          }
  };
};


1)compile time error at line 1
2)compile time error at line 2
3)the code compiles fine
4)none of the above

Ans: 3