We have sent an email with your new password.


Java 6 Test

40 Questions  I  By Pearlox
  • Share This on Twitter
  • +
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 is true regarding the continue statement in afor loop?
A.
B.
C.
D.
E.
2.  What is the result of compiling and running the following program. Select the one correct answer.class test {    public static void main(String args[]) {        char ch;        String test2 = "abcd";        String test = new String("abcd");        if(test.equals(test2)) {            if(test == test2)                ch = test.charAt(0);            else                ch = test.charAt(1);                       }        else {            if(test == test2)                ch = test.charAt(2);            else                                ch = test.charAt(3);        }        System.out.println(ch);    }}
A.
B.
C.
D.
3.  interface I {           //1  public class Inner {   ///2                    Inner ( ) {                  System .out . println ( "Inner Created" ) ;          }  };};
A.
B.
C.
D.
4.  What is the result of compiling and running the following program. Select the one correct answer.class test {    public static void main(String args[]) {     int i,j=0;     for(i=10;i<0;i--) { j++; }     switch(j) {     case (0) :         j=j+1;     case(1):         j=j+2;         break;     case (2) :         j=j+3;         break;          case (10) :         j=j+10;         break;     default :         break;     }   System.out.println(j);   }}
A.
B.
C.
D.
E.
5.  Which of the following statements are correct ?
A.
B.
C.
D.
E.
6.  Is the following statement true or false. The constructor of a class must not have a return type.
A.
B.
7.  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.
8.  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.
9.  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.
10.  Given the following declarationsString s1=new String("1")String s2=new String("2");String s3=new String("true");String s3=new String("false");Which of the following are legal operations?
A.
B.
C.
D.
E.
11.  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.
12.  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.
13.  What will happen if you attempt to compile and run the following code?.public class Main {    private int ii;    public static void main(String[] args) {        Main m = new Main();        m.m1();    }    public static void m1() {        System.out.println(ii);    }}
A.
B.
C.
D.
E.
14.  What will be the output if you compile and run the following code ?(Choose the correct answer)public class test {   public static void main(String args[]) {       String str1="abc";      String str2="def";      String str3=str1.concat(str2);      str1.concat(str2);      System.out.println(str1);   }}
A.
B.
C.
D.
E.
15.  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.
16.  Which of the following is true. Select the two correct answers
A.
B.
C.
D.
17.  class C {public static void main(String[] args) { int x=2; int y=3;   if((y==x++)|(x<++y)){                              System.out.println(x+""+y);        }}}
A.
B.
C.
D.
E.
18.  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.
19.  class base{base(int c){ System.out.println("base");}}class Super extends base{ Super() {    System.out.println("super");  }public static void main(String [] a){      base b1=new  Super();}}
A.
B.
C.
D.
20.  class C{public static void main (String[] args) {String s1="hjhh";        // 1String s2="\u0002";      //2String s3="'\\'";        //3}}
A.
B.
C.
D.
E.
21.  What all gets printed when the following code is compiled and run. Select the three correct answers.class test {    public static void main(String args[]) {        int i[] = {0,1};        try {            i[2] = i[0] + i[1];        }        catch(ArrayIndexOutOfBoundsException e1) {            System.out.println("1");        }        catch(Exception e2) {            System.out.println("2");        }        finally {            System.out.println(3);        }        System.out.println("4");       }}
A.
B.
C.
D.
22.  class C {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");}}}What is the result of attempting to compile and run the program? 
A.
B.
C.
D.
E.
23.  Public static double sin(double angle)What are the units of the "angle" argument?
A.
B.
C.
D.
24.  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);}}
A.
B.
C.
D.
E.
25.  Which of the following methods are static members of the Thread class?
A.
B.
C.
D.
E.
26.  Which of the following are true about interfaces. Select the two correct answers.
A.
B.
C.
D.
27.  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.
28.  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);    }}
29.  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.
30.  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.
31.  All classes of the java.lang package are automatically imported
A.
B.
32.  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.
33.  Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
A.
B.
C.
D.
E.
34.  class C{public static void main(String args[]) {int a = 1;a += ++a + a++;System.out.print(a);}}
A.
B.
C.
D.
E.
35.  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.
36.  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.
37.  Select the one correct answer. The smallest number that can be represented using short primitive type in Java is -
A.
B.
C.
D.
E.
38.  String s = new String("xyz");      Assuming the above declaration, which of the following statements would compile. Select the one correct answer
A.
B.
C.
D.
E.
39.  Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.
40.  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.
Back to top

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz