Java 6 Test

40 Questions  I  By Pearlox
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.  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.
2.  What gets printed when the following program is compiled and run? public class Main {    public void m1(Object o) {        System.out.println("Object");    }    public void m1(String s) {        System.out.println("String");    }    public static void main(String args[]) {        Main m = new Main();        m.m1(null);    }}
A.
B.
C.
D.
E.
3.  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.
4.  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.
5.   Each element must be unique Duplicate elements must not replace old elements. Elements are not key/value pairs.Accessing an element can be almost as fast as performing a similar operation on an array.Which of these classes provide the specified features?
A.
B.
C.
D.
E.
6.  class C {public static void main(String[] args) {  try    {        int i1=3/0;      }       System.out.println("hai");    catch(NullpointerException e)    {        }     finally    {              System.out.println("finally);       }}}
A.
B.
C.
D.
7.  if(0.0 == -0.0) {  System.out.println("true");}else{    System.out.println("false");}
A.
B.
8.  What will be the output if you compile and run the following code ?abstract class Super { abstract void amethod(); static int i;}public class Test extends Super { public static void main(String... args){ int[] arr = new int[5]; for(i=0;i < arr.length;i++) System.out.println(arr[i]); }}
A.
B.
C.
D.
E.
9.  What gets printed when the following code is compiled and run. Select the one correct answer.      public class test {          public static void main(String args[]) {           int i = 1;          do {              i--;          } while (i > 2);          System.out.println(i);          }      }             
A.
B.
C.
D.
10.   What will happen if you attempt to compile and run the following code?.public class Main {    static int j = 20;    public static void main(String[] args) {        int i = 10;        Main m = new Main();        m.m1(i);        System.out.println(i);        System.out.println(j);    }    public void m1(int x) {        x = x * 2;        j = j * 2;    }}
A.
B.
C.
D.
E.
11.  class C1{static class C2{static int i1;}public static void main(String a[]){System.out.println(C1.C2.i1);}}What is the result of attempting to compile and run the program?
A.
B.
C.
D.
12.  What all gets printed when the following code is compiled and run? Select the three correct answers.      public class xyz {         public static void main(String args[]) {            for(int i = 0; i < 2; i++) {               for(int j = 2; j>= 0; j--) {                  if(i == j) break;                  System.out.println("i=" + i + " j="+j);               }            }         }      }
A.
B.
C.
D.
E.
13.    19. What all gets printed when the following gets compiled and run. Select the two correct answers.      public class test {          public static void main(String args[]) {           String s1 = "abc";          String s2 = "abc";          if(s1 == s2)              System.out.println(1);          else              System.out.println(2);          if(s1.equals(s2))              System.out.println(3);          else              System.out.println(4);          }      }              
A.
B.
C.
D.
14.  Which are valid Java keywords.(Choose all that apply)
A.
B.
C.
D.
E.
15.  What will be the output if you compile and run the following code ?public class Test { public static void main(String[] arg){ int anar[]=new int[5]; System.out.println(anar[0]); }}
A.
B.
C.
D.
E.
16.  What is the number of bytes used by Java primitive long. Select the one correct answer.
A.
B.
C.
D.
E.
17.  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.
18.  Given the following declarations, which of the assignments given in the options below would compile. Select the two correct answers.int i = 5;boolean t = true;float f = 2.3F;double d = 2.3;
A.
B.
C.
D.
E.
19.  What all gets printed when the following program is compiled and run. Select the two correct answers.      public class test {         public static void main(String args[]) {             int i, j=1;            i = (j>1)?2:1;            switch(i) {              case 0: System.out.println(0); break;              case 1: System.out.println(1);              case 2: System.out.println(2); break;              case 3: System.out.println(3); break;            }         }      }             
A.
B.
C.
D.
20.  The constructor for the Math class is private, so it cannot be instaniated
A.
B.
21.  The Throwable class is the superclass of all exceptions in the Java language.
A.
B.
22.  Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.
23.  class C {public static void main(String[] args) {   char  c1=65;  switch(c1){       case 'A':                                             System.out.println("one");        default:                                             System.out.println("two");      case 'b':                                              System.out.println("three");}}}
A.
B.
C.
D.
E.
24.  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.
25.  You have a requirement to create a class that will store unique object elements. And you do not need to sort these elements.Which interface might be most suitable to meet your requirement?
A.
B.
C.
D.
E.
26.  class c1 extends Exception{}class c2{   static void m1()    {       throw new c1();     }  public static void main(String a[])   {              }}
A.
B.
C.
D.
27.   Which of the following statements are correct. Select the one correct answer
A.
B.
C.
D.
28.  class C{public static void main(String a[]){C c1=new C();C c2=m1(c1);C c3=new C();c2=c3;              //6anothermethod();}static C m1(C ob1){ob1 =new C();return ob1;}}After line 6, how many objects are eligible for garbage collection?
A.
B.
C.
D.
29.  Which of these statements are true. Select the two correct answers
A.
B.
C.
D.
30.  class c1{public void m1(Object o1){  System.out.println("object");}public void m1(String o1){    System.out.println("string");}public int m1(int c){    return c;}public static void main(String a[]){   c1 ob1=new c1();   ob1.m1("hai");              }}
A.
B.
C.
D.
31.  class c1{public static void main(String a[]){c1 ob1=new c1();Object ob2=ob1;System.out.println(ob2 instanceof Object);System.out.println(ob2 instanceof c1);}}
A.
B.
C.
D.
E.
32.  class A extends Thread {public void run() {System.out.print("A");}}class B {public static void main (String[] args) {A a = new A();a.start();a.start();  // 1}}
A.
B.
C.
D.
33.  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.
34.  What is the result of evaluating the expression 14 ^ 23. Select the one correct answer
A.
B.
C.
D.
E.
35.  What should be done to invoke the run() method on a thread for an object derived from the Thread class. Select the one correct answer.
A.
B.
C.
D.
36.  Class C {public static void main(String[] args) {int[]a1[]=new int[3][3]; //3int a2[4]={3,4,5,6}; //4int a2[5]; //5}}What is the result of attempting to compile and run the program ?.
A.
B.
C.
D.
E.
37.  What is the return type of method round(double d) defined in Math class.........
38.  StringBuffer objects once created can not be modified
A.
B.
39.  if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
A.
B.
C.
D.
40.  Which of the following are legal definitions of the main method that can be used to execute a class. Select the one correct answer.
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