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.   Which of the following are true. Select the one correct answers
A.
B.
C.
D.
2.   Which are legal identifier names in Java. (Choose all that apply)
A.
B.
C.
D.
E.
3.  What will be the output if you compile and run the following code ?String str=new String("honey");int begin=1;int end=3;System.out.println(str.substring(begin,end));
A.
B.
C.
D.
E.
4.  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.
5.  What is the return type of method round(double d) defined in Math class.........
6.  Which data type is wider for the purpose of casting: float or long?
A.
B.
7.  Which method defined in Integer class can be used to convert an Integer object to primitive int type.(Choose the correct answer)
A.
B.
C.
D.
E.
8.  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.
9.  At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.      void method X()  {           String r = new String("abc");          String s = new String("abc");          r = r+1; //1          r = null; //2          s = s + r; //3      } //4             
A.
B.
C.
D.
E.
10.  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.
11.  What all gets printed when the following program is compiled and run. Select the two correct answers.      public class test {         public static void main(String args[]) {             int i, j=1;            i = (j>1)?2:1;            switch(i) {              case 0: System.out.println(0); break;              case 1: System.out.println(1);              case 2: System.out.println(2); break;              case 3: System.out.println(3); break;            }         }      }             
A.
B.
C.
D.
12.  What is the signature of the run() method of the Runnable interface?
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.  class c1 extends Exception{}class c2{   static void m1()    {       throw new c1();     }  public static void main(String a[])   {              }}
A.
B.
C.
D.
15.  class H {  public static void main (String[] args) {    String s1 = "HHH";    StringBuffer sb2 = new StringBuffer(s1);    System.out.print(sb2.equals(s1) + "," + s1.equals(sb2));}}
A.
B.
C.
D.
E.
16.  class C {  public static void main ( String ka [ ] ) {          Thread t = Thread . currentThread ( ) ;          t . setPriority ( - 1 ) ;          System . out . println ( " Done ! " ) ;  }};
A.
B.
C.
D.
17.  How can you ensure that the memory allocated by an object is freed. Select the one correct answer
A.
B.
C.
D.
18.  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.
19.  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.
20.  What is the best way to findout the time/memory consuming process?
A.
B.
C.
D.
E.
21.  Which of the following are legal array declarations. Select the three correct answers
A.
B.
C.
D.
E.
22.  The Throwable class is the superclass of all exceptions in the Java language.
A.
B.
23.  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.
24.  Name the collection interface used to represent a sequence of numbers in a fixed order
25.  Which of the following statements related to Garbage Collection are correct. Select the two correct answers
A.
B.
C.
D.
26.  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.
27.   Which of the following statements are true. Select the two correct answers
A.
B.
C.
D.
28.  class c2{{ System.out.println("initializer");}public static void main(String a[]){System.out.println("main"); c2 ob1=new c2();}}
A.
B.
C.
D.
29.  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.
30.  The number of characters in an object of a class String is given by(Choose the correct answer)
A.
B.
C.
D.
E.
31.  Which of the following classes  will not allow unsynchronized read operations by multiple threads?
A.
B.
C.
D.
E.
32.   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.
33.  A signed data type has an equal number of non-zero positive and negative values available
A.
B.
34.  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.
35.  class C1{static interface I{static class C2{}}public static void main(String a[]){C1.I.C2 ob1=new C1.I.C2();System.out.println("object created");}}What is the result of attempting to compile and run the program?
A.
B.
C.
D.
36.  Class C {public static void main(String[] args) {  System.out.println(4+5+"String");}}
A.
B.
C.
D.
E.
37.  class C{public static void main(String args[]) {int a = 1;a += ++a + a++;System.out.print(a);}}
A.
B.
C.
D.
E.
38.  What all gets printed when the following gets compiled and run. Select the three correct answers.      public class test {          public static void main(String args[]) {               int i=1, j=1;              try {                  i++;                   j--;                  if(i/j > 1)                      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.
39.  Consider the following piece of code:int i;for(i=0; i<10; i++){      /* some code that doesn't modify i */}System.out.println("i="+i); /* line A */What is printed by the statement on line A?
A.
B.
C.
D.
E.
40.  What is the number of bytes used by Java primitive long. Select the one correct answer.
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.