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 a[])      {  int i1=9;  int i2;    if(i1>3) {                 i2=8;     }   System.out.println(i2);}}
A.
B.
C.
D.
E.
2.   What will happen if you attempt to compile and run the following code?.public class Main {    static int j = 20;    public static void main(String[] args) {        int i = 10;        Main m = new Main();        m.m1(i);        System.out.println(i);        System.out.println(j);    }    public void m1(int x) {        x = x * 2;        j = j * 2;    }}
A.
B.
C.
D.
E.
3.  What is the best way to findout the time/memory consuming process?
A.
B.
C.
D.
E.
4.   Given two non-negative integers a and b and a String str, what is the number of characters in the expression str.substring(a,b) . Select the one correct answer.
A.
B.
C.
D.
E.
5.  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.
6.  class C {public static void main(String[] args) {double d1 = Math.floor(0.5);double d2 = Math.floor(1.5);System.out.print(d1 + "," + d2);}}
A.
B.
C.
D.
E.
7.  class c1{   void go(){}}class c2 extends c1{ String go(){  return null;}}
A.
B.
C.
D.
8.  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.
9.  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.
10.  All classes of the java.lang package are automatically imported
A.
B.
11.  interface I{int i;                            // line 1}class C implements I{public static void main(String a[]){   System.out.println(i);   System.out.println(i++);  //line 2}}
A.
B.
C.
D.
12.  Which of the following is correct? Select the two correct answers.
A.
B.
C.
D.
13.  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.
14.  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.
15.  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. .........
16.   Each element must be unique Duplicate elements must not replace old elements. Elements are not key/value pairs.Accessing an element can be almost as fast as performing a similar operation on an array.Which of these classes provide the specified features?
A.
B.
C.
D.
E.
17.  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.
18.  Is the following statement true or false. The constructor of a class must not have a return type.
A.
B.
19.  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.
20.  Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer
A.
B.
C.
D.
E.
21.  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.
22.  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.
23.  What will happen if you attempt to compile and run the following code?.public class Main {    public static void main(String[] args) {        Main m = new Main();        m.m1();    }    public void m1() {        int ii = 012;        System.out.println(ii);    }}.............
24.  class C{static int s;public static void main(String a[]){C obj=new C();obj.m1();System.out.println(s);}void m1();{int x=1;m2(x);System.out.println(x+"");}void m2(int x){x=x*2;s=x;}}
A.
B.
C.
D.
E.
25.  String objects once created can not be modified
A.
B.
26.  Which of the following methods are static members of the Thread class?
A.
B.
C.
D.
E.
27.  What is the result of evaluating the expression 14 ^ 23. Select the one correct answer
A.
B.
C.
D.
E.
28.  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.
29.   Which of the following statements are correct. Select the one correct answer
A.
B.
C.
D.
30.  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.
31.   What gets printed when the following code is compiled and run with the following command -      java test 2      Select the one correct answer.      public class test {         public static void main(String args[]) {             Integer intObj=Integer.valueOf(args[args.length-1]);            int i = intObj.intValue();            if(args.length > 1)                System.out.println(i);            if(args.length > 0)               System.out.println(i - 1);            else                System.out.println(i - 2);         }      }              
A.
B.
C.
D.
E.
32.  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.
33.  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.
34.  The class Hashtable is used to implement which collection interface. Select the one correct answer.
A.
B.
C.
D.
E.
35.  Given the following declarations, which of the assignments given below would compile.(Choose all that apply)int k = 20;boolean b = true;float f = 2.5F;double d = 2.5;
A.
B.
C.
D.
E.
36.  if("String".replace('t','T') == "String".replace('t','T'))System.out.println("Equal");elseSystem.out.println("Not Equal");
A.
B.
C.
D.
37.  How can you ensure that the memory allocated by an object is freed. Select the one correct answer
A.
B.
C.
D.
38.  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.
39.  Which of the following modifiers can be applied to a class that is not a nested class?
A.
B.
C.
D.
40.  What is printed by the following code fragment?int[] a = {0,1,2,3,4,5,6};System.out.println(a.length);
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.