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

      Next        
Your Ad Here
Q. No Question
1 public class MyClass{
      int x = 10;
      static final int y= 5;
     
      public void method (int z){
             int a = 10;
             final float b = 10;

             class LocalClass {
                      int c = 3;
                     
                      public void method (int d){
                             System.out.println (??);         // -- 1
            }
       }
      
        public static void main (String args[]){
               new MyClass();
       }
}
Which of the following variable names can be replaced ?? at line no marked as 1,without compiler error?
 
A x
B a
C b
D c
 
2 public class MyClass{
       public static void main (String args[]){
             String str = "Hello World";
             System.out.print(str.indexOf('d'));
             System.out.print(str.indexOf('h'));
             System.out.print(str.indexOf('a'));
      }
}
What will be the output?
 
A 10    -1    -1
B 9      -1     -1
C 10     0     -1
D 10     1    -1  
 
3 What is the range of values that can be stored in a short primitive variable?
 
A 0 - 656535
B -32768 to 32767
C -32768 to 32768
D -32767 to 32768
 
4 Which of the following lines will compile without warning or error.
 
A float f=1.3;
B int i=10;
C byte b=257;
D char c="a";
 
5

What will happen if you try to compile and run the following code  ?
public class MyClass {
         public static void main (String arguments[])  {
                   amethod( arguments) ;
         }
         public void amethod (String[] arguments)  {
                   System.out.println (arguments) ;
                   System.out.println (arguments[1]) ;
        }
}

 
A Error Can't make static reference to void amethod.
B Error Incorrect main method.
C amethod must be declared with String
D Compiles and executes fine.
 
6 Which of the following will compile without error ?
 
A import java.util.*;
package mypack;
class MyClass {}
B package mypack;
import java.uril.*;
class MyClass{}
C  /*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}
D All of the above
 
7 Float f= new Float( 1.0F );
String str = "value is " +f;
System.out.println( str );

What will be the output of executing the above code snippet?
 
A Compiler error invalid character in constructor
B Runtime exception invalid character in constructor.
C Compiles and prints 'value is 1.0'
D Compiles and prints 'value is 1'
 
8 Which of the following are java keywords  ?
 
A null
B const
C volatile
D true
 
9 What will be printed out if this code is run with the following command line : java myprog good morning
public class myprog {
             public static void main (String argv[]) {
                      System.out.println(argv[2])
            }
}
 
A myprog
B good
C morning
D Exception raised: java.lang.ArrayIndexOutOfBoundsException: 2
 
10 What is the range of a byte
 
A 0 - 256
B -128 to 127
C -127 to 128
D -255 to 256
 
      Next        
Your Ad Here
Logo
 
All rights reserved.  Terms and Conditions