Sun Certified Programmer for Java 2 Platform 1.4 (CX-310-035) Practice Questions

    Previous          
Q. No Question
11 Which of the following are legal identifiers ?
 
A 1variable
B variable1
C $anothervar
D _anothervar
E %anothervar
 
12 What will happen when you compile the following code
public class MyClass{
       static int i;
        public static void main (String argv[]) {
             System.out.println(i) ;
        }
}
 
A 0
B 1
C Compiler Error variable 'i' may not have initialized.
D null
 
13 What will be the output on executing the following code.
public class MyClass {
       public static void main (String args[] ) {
              int abc[] = new int [] {1, 2, 3, 4};
              System.out.println(abc[2]);
       }
}
 
A ArrayIndexOutofBoudsException will be thrown.
B 2
C 3
D 4
 
14 What will be the output on executing the following code.
public class MyClass {
       public static void main (String args[] ) {
              int abc[] = new int [5];
              System.out.println(abc);
       }
}
 
A Error array not initialized
B 5
C null
D Print some junk characters
 
15

What will be the output on executing the following code.
public class MyClass {
       public static void main (String args[] ) {
              int abc[] = new int [5];
              System.out.println(abc[0]);
       }
}

 
A Error array not initialized
B 5
C 0
D Print some junk characters
 
16 What will be the result of attempting to compile and run the following code  ?
abstract class MineBase {
     abstract void amethod() ;
       static int i;
}
 
public class Mine extends MineBase  {
         public static void main( String argv[]) {
                 int[] ar=new int[5];
                 for (i=0;i < ar.length;i++)
                       System.out.println (ar[i]) ;
          }
}
 
A  A sequence of 5 0's will be printed
B Error: variable 'ar' may not have initialized .
C  Error Mine must be declared abstract
D Error MineBase cannot be declared abstract.
 
17 What will be printed out if you attempt to compile and run the following code ?
     int i=1;
      switch (i)  {
              case 0:
                     System.out.println ("zero") ;
                     break;
              case 1:
                    System.out.println("one") ;
                    break;
              case 2:
                     System.out.println("two") ;
                     break;
               default:
                      System.out.println("default") ;
        }
 
A one
B zero
C one default
D one two default
 
18

What will be printed out if you attempt to compile and run the following code ?
     int i=1;
      switch (i)  {
              case 0:
                     System.out.println ("zero") ;
                     break;
              case 1:
                    System.out.println("one") ;
              case 2:
                     System.out.println("two") ;
                     break;
        }

 
A zero
B one
C one two
D Error no default specified.
 
19 What will be printed out if you attempt to compile and run the following code ?
     int i=10;
      switch (i)  {
              default:
                     System.out.println("Default");
              case 0:
                     System.out.println ("zero") ;
                     break;
              case 1:
                    System.out.println("one") ;
              case 2:
                     System.out.println("two") ;
                     break;
        }
 
A default
B default zero
C Error , default cannot be the first statement in switch.
D default  zero  one two
 
20 Which of the following data types can appear inside a switch statement as its label ?
 
A String
B char
C int
D byte
 
    Previous