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.


Question Excerpt

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
1.  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.
2.  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.
3.  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.
4.  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.
5.  The documentation of a class lists a method castToIntArray that has adouble array as a formal parameter and returns an array of integers.What is the signature of the method?
A.
B.
C.
D.
E.
6.  What is the number of bytes used by Java primitive long. Select the one correct answer.
A.
B.
C.
D.
E.
7.  In Java, elements of an array are automatically initialized to somedefault value.What is the default value for the elements of an array of integers?
A.
B.
C.
D.
E.
8.  Which of the following statements related to Garbage Collection are correct. Select the two correct answers
A.
B.
C.
D.
9.  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.
10.  An abstract class must have at least one abstract method
A.
B.
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 C{public static void main (String[] args) {byte b1=33;              //1b1++;                    //2byte b2=55;              //3b2=b1+1;                 //4System.out.println(b1+""+b2);}}
A.
B.
C.
D.
E.
13.  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.
14.  You want to initialize all of the elements of a double array a to thesame value equal to 1.5.What could you write?Assume that the array has been correctly initialized
A.
B.
C.
D.
E.
15.  class C{public static void main(String[] args) {  try    {        int i1=3/0;      }    catch(Exception e)    {     System.out.println("exception1");     }    catch(NullPointerException e)    {    System.out.println("exception2");        }     finally    {              System.out.println("finally");       }}}
A.
B.
C.
D.
E.
16.  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.
17.  What is the result of evaluating the expression 14 ^ 23. Select the one correct answer
A.
B.
C.
D.
E.
18.  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.
19.  Which of the following are true about interfaces. Select the two correct answers.
A.
B.
C.
D.
20.  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.
21.  All classes of the java.lang package are automatically imported
A.
B.
22.  What is the name of the Collection interface used to represent elements in a sequence (in a particular order). (Choose the correct answer)
A.
B.
C.
D.
E.
23.  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.
24.  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.
25.  What gets printed when the following program is compiled and run. Select the one correct answer.public class incr {    public static void main(String args[]) {        int i , j;        i = j = 3;        int n = 2 * ++i;        int m = 2 * j++;        System.out.println(i + " " + j + " " + n + " " + m);    }}
A.
B.
C.
D.
E.
26.  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.
27.    19. 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 = "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.
28.  What is the default priority of a newly created thread
A.
B.
C.
D.
29.  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.
30.  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.
31.  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.
32.  class C {  public static void main ( String ka [ ] ) {          Thread t = Thread . currentThread ( ) ;          t . setPriority ( - 1 ) ;          System . out . println ( " Done ! " ) ;  }};
A.
B.
C.
D.
33.  Which of these statements are true. (Choose all that apply)
A.
B.
C.
D.
E.
34.  Which of these statements are true. Select the two correct answers
A.
B.
C.
D.
35.  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.
36.  class C{public static void main (String[] args) {String s1="hjhh";        // 1String s2="\u0002";      //2String s3="'\\'";        //3}}
A.
B.
C.
D.
E.
37.  A signed data type has an equal number of non-zero positive and negative values available
A.
B.
38.  What will be the output if you compile and run the following code ?public class Main {    public static void main(String[] arg) {    method1(arg);    }    public void method1(String... arguments) {    System.out.println(arguments);    }}
A.
B.
C.
D.
E.
39.   Which are legal identifier names in Java. (Choose all that apply)
A.
B.
C.
D.
E.
40.  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.
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.