We have sent an email with your new password.


Java 6 Test

40 Questions  I  By Pearlox
Java Quizzes & Trivia
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 true. Select the one correct answers
A.
B.
C.
D.
2.  System.out.println("String".substring(0,4));This statement will Print
A.
B.
C.
D.
3.   class C extends Thread{public static void main(String argv[]){          C b = new C();          b.run();  }  public void start(){          for (int i = 0; i <10; i++){                  System.out.println("Value of i = " + i);          }  }}
A.
B.
C.
D.
4.  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.
5.  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.
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.  class C{static String m(int i) {return "int";}static String m(float i) {return "float";}public static void main (String[] args) {long a1 = 1; double b1 = 2;System.out.print(m(a1)+","+ m(b1));}}
A.
B.
C.
D.
E.
8.  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.
9.  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);    }}
10.  Which of the following is correct? Select the two correct answers.
A.
B.
C.
D.
11.   In implementing two classes Employee and Manager, such that each Manager is an Employee, what should be the relationship between these classes. Select the one correct answer.
A.
B.
C.
D.
E.
12.  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.
13.  What is the number of bytes used by the primitive type long. (Select the best answer)
A.
B.
C.
D.
E.
14.  class A{static String m(float i) {return "float";}static String m(double i) {return "double";}public static void main (String[] args) {int a1 = 1; long b1 = 2;System.out.print(m(a1)+","+ m(b1));}}
A.
B.
C.
D.
E.
15.  If a base class has a method defined as      void method() { }      Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
A.
B.
C.
D.
16.  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.
17.  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.
18.  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.
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.  class c2{{ System.out.println("initializer");}public static void main(String a[]){System.out.println("main"); c2 ob1=new c2();}}
A.
B.
C.
D.
21.  How would the number 5 be represented in hex using up-to four characters? ............
22.  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.
23.  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.
24.  if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
A.
B.
C.
D.
25.  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.
26.  Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
A.
B.
C.
D.
27.  What will be the output if you compile and run the following code ?int i=1; switch (i) { case 0: System.out.println("number"); break; case 1: System.out.println("one"); case 5: System.out.println("two");case 10: System.out.println("three"); default: System.out.println("default"); }
A.
B.
C.
D.
E.
28.  Which of the following statements about arrays are true.(Choose all that apply)
A.
B.
C.
D.
E.
29.  Name the collection interface used to represent a sequence of numbers in a fixed order
30.  Which data type is wider for the purpose of casting: float or long?
A.
B.
31.  class c1{static{System.out.println("static");}public static void main(String a[]){System.out.println("main");}}
A.
B.
C.
D.
E.
32.  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.
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.   Which are legal identifier names in Java. (Choose all that apply)
A.
B.
C.
D.
E.
35.  What will be the output if you compile and run the following code ?String str=new String("honey");int begin=1;int end=3;System.out.println(str.substring(begin,end));
A.
B.
C.
D.
E.
36.  What will happen when you attempt to compile and run the following code?class TestRunnable implements Runnable {    int k = 0;    public int run() {        while (true) {            k++;            System.out.print("k=" + k);        }        return 50;    }}
A.
B.
C.
D.
E.
37.   Which of the following statements are true. Select the two correct answers
A.
B.
C.
D.
38.  interface I{void f1();              // 1public void f2();       // 2protected void f3();    // 3private void f4();      // 4abstract void f5();     // 5}
A.
B.
C.
D.
E.
39.  What all gets printed when the following gets compiled and run. Select the three correct answers.      public class test {          public static void main(String args[]) {               int i=1, j=1;              try {                  i++;                   j--;                  if(i/j > 1)                      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.
40.  class C{public static void main(String args[]) {int a = 1;a += ++a + a++;System.out.print(a);}}
A.
B.
C.
D.
E.
Back to top

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz