Java 6 Test

40 Questions  I  By Pearlox
Please take the quiz to rate it.

Java Quizzes & Trivia
Pearlox Corp. Java 6 Test

  
Changes are done, please start the quiz.


Questions and Answers Excerpt

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
1.  Which of these are legal array declarations or definitions? Select the two correct answers.
A.
B.
C.
D.
2.  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.
3.  Which of the following statements are true. Select the one correct answer.
A.
B.
C.
D.
4.  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. .........
5.  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.
6.  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.
7.  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.
8.  class C{public static void main (String[] args) {String s1="hjhh";        // 1String s2="\u0002";      //2String s3="'\\'";        //3}}
A.
B.
C.
D.
E.
9.  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.
10.  class c2{{ System.out.println("initializer");}public static void main(String a[]){System.out.println("main"); c2 ob1=new c2();}}
A.
B.
C.
D.
11.  Class C {public static void main(String[] args) {  System.out.println(4+5+"String");}}
A.
B.
C.
D.
E.
12.  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);    }}
13.  The number of characters in an object of a class String is given by(Choose the correct answer)
A.
B.
C.
D.
E.
14.  if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
A.
B.
C.
D.
15.  Select the one correct answer. The number of characters in an object of a class String is given by
A.
B.
C.
D.
16.  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.
17.  Which defines a legal method declaration ?(Choose all that apply)
A.
B.
C.
D.
E.
18.  Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class.
A.
B.
C.
D.
19.  class C{ public static void main(String a[])      {  int i1=9;  int i2;    if(i1>3) {                 i2=8;     }   System.out.println(i2);}}
A.
B.
C.
D.
E.
20.  An abstract class must have at least one abstract method
A.
B.
21.  All classes of the java.lang package are automatically imported
A.
B.
22.  Which of the following are correct. Select the one correct answer.
A.
B.
C.
D.
23.  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.
24.  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.
25.  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.
26.  Which of the following are true about interfaces. Select the two correct answers.
A.
B.
C.
D.
27.  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.
28.  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.
29.  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.
30.  The Throwable class is the superclass of all exceptions in the Java language.
A.
B.
31.  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.
32.  How would the number 5 be represented in hex using up-to four characters? ............
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[]) {           String s1 = "abc";          String s2 = new String("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.
34.  Which of the following are legal array declarations. Select the three correct answers
A.
B.
C.
D.
E.
35.  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.
36.  String objects once created can not be modified
A.
B.
37.  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.
38.  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.
39.  class bike{}class arr extends bike{public static void main(String[] args) {arr[] a1=new arr[2];    bike[] a2;             a2=a1;                 //3arr[] a3;              a3=a1;                //5}}
A.
B.
C.
D.
E.
40.  In which all cases does an exception gets generated. Select the two correct answers int i = 0, j = 1;
A.
B.
C.
D.
Back to top

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz
We have sent an email with your new password.