Java 6 Test

40 Questions  I  By Pearlox on April 20, 2010
Pearlox Corp.Java 6 Test

  
Changes are done, please start the quiz.


Question Excerpt

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
1.  Which of the following are correct. Select the one correct answer.
A.
B.
C.
D.
2.  System.out.println("String".substring(0,4));This statement will Print
A.
B.
C.
D.
3.  What will be the output if you compile and run the following code ?public class Main{ private static int i; public static void main(String[] args){ System.out.println(i); }}
A.
B.
C.
D.
E.
4.  Which defines a legal method declaration ?(Choose all that apply)
A.
B.
C.
D.
E.
5.  When a byte is added to a char, what is the type of the result?
A.
B.
C.
D.
6.  class C{public static void main(String[] args) {  try    {        int i1=3/0;      }    catch(Exception e)    {     System.out.println("exception1");     }    catch(NullPointerException e)    {    System.out.println("exception2");        }     finally    {              System.out.println("finally");       }}}
A.
B.
C.
D.
E.
7.  Which data type is wider for the purpose of casting: float or long?
A.
B.
8.  What is the number displayed when the following program is compiled and run.class test {    public static void main(String args[]) {        test test1 = new test();            System.out.println(test1.xyz(100));        }    public int xyz(int num) {        if(num == 1) return 1;        else return(xyz(num-1) + num);    }}
9.   Which are legal identifier names in Java. (Choose all that apply)
A.
B.
C.
D.
E.
10.  What is the singleton access modifier ?
A.
B.
C.
D.
11.  Considerint a = 6;int b = 12;while(a      System.out.println("In the loop");      a+=2;      b-=2;}How many times is the phrase "In the loop" printed?
A.
B.
C.
D.
E.
12.  class c1{   public void m1()    {       System.out.println("m1 method in C1 class");     }}class c2{  public c1 m1()   {     return new c1(){       public void m1()          {              System.out.println("m1 mehod in anonymous class");    }};}public static void main(String a[]) {                c1 ob1 =new c2().m1();        ob1.m1();}}
A.
B.
C.
D.
E.
13.  What is the default priority of a newly created thread
A.
B.
C.
D.
14.  class C{int i;public static void main (String[] args) {int i; //1private int a = 1; //2protected int b = 1; //3public int c = 1; //4System.out.println(a+b+c); //5}}
A.
B.
C.
D.
E.
15.  class C{public static void main(String[] args) {  try    {        try           {               try                 {                   }                 catch(RuntimeException e)                 {                  }             }           catch(Exception e)           {            }                    }    catch(NullPointerException e)    {        }     finally    {              System.out.println("finally");       }}}
A.
B.
C.
D.
16.  1. StringBuffer s1 = new StringBuffer("abc");2. StringBuffer s2 = s1;3. StringBuffer s3 = new StringBuffer("abc");How many objects are created ?
A.
B.
C.
D.
17.  The number of characters in an object of a class String is given by(Choose the correct answer)
A.
B.
C.
D.
E.
18.  What is the result of compiling and running the following program. Select the one correct answerclass test {    public static void main(String args[]) {        int[] arr = {1,2,3,4};        call_array(arr[0], arr);        System.out.println(arr[0] + "," + arr[1]);            }    static void call_array(int i, int arr[]) {        arr[i] = 6;        i = 5;    }    }
A.
B.
C.
D.
19.  What gets written on the screen when the following program is compiled and run. Select the one right answer.      public class test {         public static void main(String args[]) {          int i;         float  f = 2.3f;         double d = 2.7;         i = ((int)Math.ceil(f)) * ((int)Math.round(d));                System.out.println(i);         }      }
A.
B.
C.
D.
E.
20.  Select the one correct answer. The number of characters in an object of a class String is given by
A.
B.
C.
D.
21.  class C {  public static void main ( String ka [ ] ) {          Thread t = Thread . currentThread ( ) ;          t . setPriority ( - 1 ) ;          System . out . println ( " Done ! " ) ;  }};
A.
B.
C.
D.
22.  A program needs to store the name, salary, and age of employees in years. Which of the following data types should be used to create the Employee class. Select the three correct answer
A.
B.
C.
D.
E.
23.  interface I {           //1  public class Inner {   ///2                    Inner ( ) {                  System .out . println ( "Inner Created" ) ;          }  };};
A.
B.
C.
D.
24.  What is printed by the following code fragment?int[] a = {0,1,2,3,4,5,6};System.out.println(a.length);
A.
B.
C.
D.
E.
25.   Which of the following statements are correct. Select the one correct answer
A.
B.
C.
D.
26.  What gets printed when the following program is compiled and run? Select the one correct answer.class xyz {    static int i;    public static void main(String args[]) {        while (i < 0) {            i--;        }        System.out.println(i);    }}
A.
B.
C.
D.
E.
27.  Which of the following statements about this code are true?class Testing extends Thread{    public void run(){        for(int i =0; i < 2; i++){            System.out.println(i);        }        }    }public class Sub{    public static void main(String[] args){        Sub m = new Sub();        m.go(new Testing());        }    public void go(Testing t){        t.start();        }    }
A.
B.
C.
D.
E.
28.  String s = new String("xyz");      Assuming the above declaration, which of the following statements would compile. Select the one correct answer
A.
B.
C.
D.
E.
29.  class A extends Thread {  private int i;  public void run() {i = 1;}  public static void main(String[] args) {    A a = new A();    a.run();    System.out.print(a.i);}}How many threads are created in this Program?
A.
B.
C.
D.
E.
30.  What will be the output if you compile and run the following code ?public class Main {    public static void main(String[] arg) {    method1(arg);    }    public void method1(String... arguments) {    System.out.println(arguments);    }}
A.
B.
C.
D.
E.
31.  What gets printed when the following program is compiled and run? (Choose the correct answer)class Main {    static int i;    public static void main(String... args) {        while (i < 0) {            i--;        }        System.out.println(i);    }}
A.
B.
C.
D.
E.
32.  In Java, elements of an array are automatically initialized to somedefault value.What is the default value for the elements of an array of integers?
A.
B.
C.
D.
E.
33.  Is the following statement true or false. The constructor of a class must not have a return type.
A.
B.
34.  String objects once created can not be modified
A.
B.
35.  Name the collection interface used to represent a sequence of numbers in a fixed order
36.  import java.util.*;class  C{  final Vector v;  C()  {          v=new Vector();  }   C(int i)  {         }  public void someMethod()  {          System.out.println(v.isEmpty());  }}
A.
B.
C.
D.
37.  Which of the following statements are true. Select the one correct answer.
A.
B.
C.
D.
38.  Which declares a valid main method. (Choose all that apply)
A.
B.
C.
D.
E.
39.  Which of the following modifiers can be applied to a class that is not a nested class?
A.
B.
C.
D.
40.  class C {public static void main(String[] args) {double d1 = Math.floor(0.5);double d2 = Math.floor(1.5);System.out.print(d1 + "," + d2);}}
A.
B.
C.
D.
E.
Back to top


to post comments.

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz