Java Paper - 4

16 Questions | Total Attempts: 804

SettingsSettingsSettings
Please wait...
Java Paper - 4

Questions and Answers
  • 1. 
    Which of the following are valid inside a class?
    1. protected abstract void display();
    2. static final void display(){}
    3. public synchronized final void display() {}
    4. private native void display1(); 
    • A. 

      1 and 3

    • B. 

      2 and 4

    • C. 

      1 only

    • D. 

      All

  • 2. 
    To compile any source java file, which of the following must be true. 
    • A. 

      It should have default package statement

    • B. 

      file extension must be .java

    • C. 

      File extension must be .Java

    • D. 

      It should have public static void main().

  • 3. 
    Public interface Value {     String value = 4; }What is following is true about “value” inside interface.1.    final String value = 4; 2.    public String value = 4; 3.    abstract String value = 4; 4.    volatile String value = 4; 5.    protected String value = 4; 
    • A. 

      1, 2

    • B. 

      1, 3

    • C. 

      2, 4

    • D. 

      4, 5

  • 4. 
    What will be the output of the program? public class ArrayCopy {        public static void main(String [] args)         {            ArrayCopy arrayCopy = new ArrayCopy();            arrayCopy.display();        }        void display()         {            long [] array1 = {3,4,5};            long [] array2 = arrayPrint(array1);            System.out.print(array1 [0] + array1 [1] + array1 [2] + " ");            System.out.println(array2 [0] + array2 [1] + array2 [2]);        }        long [] arrayPrint(long [] a3)         {            a3[1] = 6;            return a3;        }}
    • A. 

      12, 14

    • B. 

      14, 14

    • C. 

      3 4 5 3 6 5

    • D. 

      3 6 5 3 6 5

  • 5. 
    What will be the output of the program?public class IntegerEqual{    public static void main(String [] args)    {        int a = 100;        Integer  b = new Integer("100");        boolean c = (a == b);        System.out.println(c);    }}
    • A. 

      True

    • B. 

      False

    • C. 

      Compilation fails

    • D. 

      An exception is thrown at runtime

  • 6. 
    What will be the output of the program? public class LeftShift {       public static void main(String [] args)     {        int a = 4;                a = a << 2;                System.out.println("a = " + a);    }}
    • A. 

      2

    • B. 

      4

    • C. 

      8

    • D. 

      16

  • 7. 
    What will be the output of the program?public class Test {       public static void main(String[] args) {              try {                     int i = 0;                     int j = j / i;              } catch (Exception e) {                     System.out.println("Exception");              } catch (ArithmeticException ae) {                     System.out.println(" Arithmetic Exception");              }              System.out.println("finished");       } } 
    • A. 

      Finished

    • B. 

      Exception

    • C. 

      Compilation fails.

    • D. 

      Arithmetic Exception

  • 8. 
    What will be the output of the program? public class PrintTest {     public static void main(String [] args)     {        try         {            System.out.print("X");        }          catch (Exception ex)         {            System.out.print("Y");         }          finally         {            System.out.print("Z");         }          System.out.print("?");     }      public static void doNothing()  throws RuntimeException{        try {                    }        catch(Exception e) {            throw new printException();        }    }        class printException extends RuntimeException    {        private static final long serialVersionUID = 1L;            }} 
    • A. 

      XY?

    • B. 

      XZ?

    • C. 

      XYZ?

    • D. 

      YZ?

  • 9. 
    Which collection class allows you to grow or shrink its size?
    • A. 

      Java.util.HashSet

    • B. 

      Java.util.LinkedHashSet

    • C. 

      Java.util.LinkList

    • D. 

      Java.util.ArrayList

  • 10. 
    Which constructs an anonymous inner class instance?
    • A. 

      Runnable r = new Runnable() { };

    • B. 

      Runnable r = new Runnable(public void run() { });

    • C. 

      Runnable r = new Runnable { public void run(){}};

    • D. 

      System.out.println(new Runnable() {public void run() { }});

  • 11. 
    Which one of following option will not stop thread execution?
    • A. 

      SetPriority() method on a Thread object.

    • B. 

      Wait() method on an object.

    • C. 

      Read() method on an InputStream object.

    • D. 

      Calling read() method on an InputStream object

  • 12. 
    Void testObject() {     class1 object1 = new class1 ();    class2 object2 = new class2 ();    object1.s(object2);     object2 = null;    object1 = null;     System.out.println("start completed");}When the class2 object, will be eligible for garbage collection? 
    • A. 

      After line 5

    • B. 

      After line 6

    • C. 

      After line 7

    • D. 

      None of the above

  • 13. 
    What is will be output of following programpublic class TestFinal {    private final int a = 10;    private static final int b;    private final int c;    {        b = 20;    }    TestFinal() {        c = 30;    }        public static void main(String[] args) {        System.out.println("a " + a);        System.out.println("a " + b);        System.out.println("a " + c);    }}
    • A. 

      10 20 30

    • B. 

      10 0 30

    • C. 

      Compilation error

    • D. 

      10 Garbage value 30

  • 14. 
    What will be the output of the program? public class Test {      public static void main(String[] args)     {         int x = 0;          assert (x > 0) ? true : false ;         System.out.println("finished");      } }
    • A. 

      Finished

    • B. 

      Compiliation fails.

    • C. 

      Run time fails

    • D. 

      None of the above

  • 15. 
    What will be output of following program. public class TestMain {        public static void main(String[] args) {              int a = 5;              int b = a++ * a++;                           System.out.println(" a = " + a);              System.out.println(" b = " + b);       } 
    • A. 

      6, 30

    • B. 

      7, 42

    • C. 

      7, 30

    • D. 

      6, 36

  • 16. 
    Select the ones you like
    • A. 

      Option1

    • B. 

      Option2

    • C. 

      Option3

    • D. 

      Option4

Back to Top Back to top