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

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
1.  class C{public static void main(String args[]) {int a = 1;a += ++a + a++;System.out.print(a);}}
A.
B.
C.
D.
E.
2.  Which defines a legal method declaration ?(Choose all that apply)
A.
B.
C.
D.
E.
3.  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.
4.  What kind of objects is StringBuffer ?
A.
B.
C.
D.
E.
5.  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.
6.  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.
7.  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.
8.  Using up to four characters what is the Java representation of the number 23 in hex?..............
9.  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.
10.  class C {  private String get ( String str ) {          try          {                  throw new Exception ( ) ;                  return str ;          }          catch ( Exception e )          {                  return null ;          }  }  public static void main ( String peace [ ] ) {          try          {                  System.out.println ( ( new C ( ) ).get ( " C " ) ) ;          }          catch ( Exception e )          {                  System.out.println( "Exception" ) ;          }  }};
A.
B.
C.
D.
11.  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.
12.  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.
13.  class C{static int f1(int i) {System.out.print(i + ",");return 0;}public static void main (String[] args) {int i = 0;i = i++ + f1(i);System.out.print(i);}}Prints: 0,0Prints: 1,0Prints: 0,1
A.
B.
C.
D.
E.
14.  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.
15.  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.
16.  abstract class A {}   // 1transient class B {}  // 2private class C {}    // 3static class D {}     // 4Which of these declarations will not produce a compile-time error?
A.
B.
C.
D.
E.
17.  What is the range of values that can be specified for an int. Select the one correct answer.
A.
B.
C.
D.
E.
18.  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.
19.  Public static double sin(double angle)What are the units of the "angle" argument?
A.
B.
C.
D.
20.  What is the singleton access modifier ?
A.
B.
C.
D.
21.  Which of the following modifiers can be applied to a class that is not a nested class?
A.
B.
C.
D.
22.  class command {public static void main (String[] a1) {System.out.println(a1.length());         //1System.out.println(a1[0]);               //2System.out.println(a1);                  //3        //2}}
A.
B.
C.
D.
23.  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.
24.  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.
25.  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.
26.  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.
27.  What gets printed when the following program is compiled and run? (Choose the correct answer)class Main {    public static void main(String[] args) {        int i;        do {            i++;        }        while(i < 0);        System.out.println(i);    }}
A.
B.
C.
D.
E.
28.  abstract class vehicle{abstract public void speed();}class car extends vehicle{public static void main (String args[]) {vehicle ob1;        ob1=new car();   //1}}
A.
B.
C.
D.
29.  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.
30.  In which all cases does an exception gets generated. Select the two correct answers int i = 0, j = 1;
A.
B.
C.
D.
31.  Name the collection interface used to represent a sequence of numbers in a fixed order
32.  Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
A.
B.
C.
D.
33.  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.
34.  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.
35.  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.
36.  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.
37.  To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer
A.
B.
C.
D.
E.
38.  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.
39.   Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.
40.   Which are legal identifier names in Java. (Choose all that apply)
A.
B.
C.
D.
E.
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.