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.  Name the collection interface used to represent collections that maintain unique elements..........
2.  What will be the output if you compile and run the following code ?public class Main {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");}}}
A.
B.
C.
D.
E.
3.  Select the one correct answer. The smallest number that can be represented using short primitive type in Java is -
A.
B.
C.
D.
E.
4.  What will happen if you attempt to compile and run the following code?.public class Main {    public static void main(String[] args) {        Main m = new Main();        m.m1();    }    public void m1() {        int ii = 012;        System.out.println(ii);    }}.............
5.  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.
6.  Which keyword when applied on a method indicates that only one thread can execute this method at a time. (Choose the correct answer)
A.
B.
C.
D.
E.
7.  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.
8.  class base{base(){ System.out.println("base");}base(int i1){}}class Super extends base{ Super() {     System.out.println("super");      super(1);      }public static void main(String [] a){      base b1=new  Super();}}
A.
B.
C.
D.
9.  Which keyword when applied on a method indicates that only one thread should execute the method at a time. Select the one correct answer
A.
B.
C.
D.
E.
10.  Which of the following modifiers can be applied to a class that is not a nested class?
A.
B.
C.
D.
11.  Which of the following methods can be legally inserted in place of the comment //Insert Method Here ..class Main{ public void method1(int i) { }}public class Sub extends Main{ public static void main(String[] args){ } //Insert Method Here ..}
A.
B.
C.
D.
E.
12.  class c2{final int i1;c2(){i1=i1+1;}{i1=2;}public static void main(String a[]){c2 ob1=new c2();System.out.println(ob1.i1);}}
A.
B.
C.
D.
13.  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.
14.  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.
15.  Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
A.
B.
C.
D.
16.  In which all cases does an exception gets generated. Select the two correct answers int i = 0, j = 1;
A.
B.
C.
D.
17.  if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
A.
B.
C.
D.
18.  Consider the codeint[] x = {5,6,7,8,9};int[] y = x;y[2] = 10;What is the value of x[2]?
A.
B.
C.
D.
E.
19.  What is the default priority of a newly created thread
A.
B.
C.
D.
20.  Name the collection interface used to represent a sequence of numbers in a fixed order
21.  Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer
A.
B.
C.
D.
E.
22.  What gets printed when the following program is compiled and run? Select the one correct answer.class test { public static void main(String args[]) { int i; do { i++; } while(i < 0); System.out.println(i); }}
A.
B.
C.
D.
E.
23.   Which of the following statements are correct. Select the one correct answer
A.
B.
C.
D.
24.  interface I{final class C1   {     //1       static int i=9;;  //2 }}class C2 implements I{ public static void main(String a[]){    System.out.println(I.C1.i);  ///3}}
A.
B.
C.
D.
E.
25.   What happens when the following program is compiled and then the command "java check it out" is executed. Select the one correct answer.class check {    public static void main(String args[]) {        System.out.println(args[args.length-2]);    }}
A.
B.
C.
D.
E.
26.  class C {static void m1(Object x) {System.out.print("Object");}static void m1(String x) {System.out.print("String");}public static void main(String[] args) {m1(null);}}
A.
B.
C.
D.
27.  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.
28.  class C1{static interface I{static class C2{}}public static void main(String a[]){C1.I.C2 ob1=new C1.I.C2();System.out.println("object created");}}What is the result of attempting to compile and run the program?
A.
B.
C.
D.
29.  Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer
A.
B.
C.
D.
E.
30.  Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.
A.
B.
31.  interface I{int i;                            // line 1}class C implements I{public static void main(String a[]){   System.out.println(i);   System.out.println(i++);  //line 2}}
A.
B.
C.
D.
32.  What will be the output if you compile and run the following code ?int h=15;switch (h) {         default:         System.out.println("default");         case 20:         System.out.println("20");         break;         case 21:         System.out.println("21");         case 22:         System.out.println("22");        }
A.
B.
C.
D.
E.
33.  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[]) {               int i=1, j=1;              try {                  i++;                   j--;                  if(i == j)                      i++;              }              catch(ArithmeticException e) {                  System.out.println(0);              }              catch(ArrayIndexOutOfBoundsException e) {                  System.out.println(1);              }              catch(Exception e) {                  System.out.println(2);              }              finally {                  System.out.println(3);              }              System.out.println(4);           }      }             
A.
B.
C.
D.
E.
34.  What will be the output if you compile and run the following code ?public class Main { public static void main(String[] args){ int vest[]=new int[]{1,2,3}; System.out.println(vest[1]); }}
A.
B.
C.
D.
E.
35.  void method() { }Which of the following declares a legal override of this method in a sub class.(Choose all that apply)
A.
B.
C.
D.
E.
36.  What all gets printed when the following program is compiled and run. Select the one correct answer.      public class test {         public static void main(String args[]) {             int i=0, j=2;            do {               i=++i;               j--;            } while(j>0);            System.out.println(i);         }      }              
A.
B.
C.
D.
E.
37.  What gets printed when the following program is compiled and run? Select the one correct answer.class xyz {     public static void main(String args[]) {        int i,j,k;        for (i = 0; i < 3; i++) {            for(j=1; j < 4; j++) {                for(k=2; k<5; k++) {                    if((i == j)   && (j==k))                        System.out.println(i);                }                            }        }    }}
A.
B.
C.
D.
E.
38.  What gets printed when the following program is compiled and run? Select the one correct answer.class test {    static boolean check;    public static void main(String args[]) {        int i;        if(check == true)            i=1;        else            i=2;        if(i=2) i=i+2;        else i = i + 4;        System.out.println(i);     }}
A.
B.
C.
D.
E.
39.  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.
40.  What is returned when the method substring(2, 4) is invoked on the string "example"? Include the answer in quotes as the result is of type String. .........
Back to top


to post comments.

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz