Java Toughest Exam Quiz! Trivia

40 Questions | Total Attempts: 108

SettingsSettingsSettings
Please wait...
Java Quizzes & Trivia

.


Questions and Answers
  • 1. 
    Consider the following code: Line no 1:class Outer{ Line no 2:public static class Inner{ Line no 3:} Line no 4:public static void display(){ } } Line no 5:public class Test Line no 6:{ Line no 7:public static void main(String args[]) Line no 8:{ Line no 9://Replace with code from the option below Line no 10:}} Which of the following option when replaced at line no 9,instantiates an instance of the nested class?
    • A. 

      Outer o = new Outer(); Outer.Inner oi = o.new Outer.Inner();

    • B. 

      Outer.Inner o = new Outer.Inner();

    • C. 

      Outer.Inner oi = new Inner();

    • D. 

      Inner oi = new Outer.Inner();

  • 2. 
    Which of the following are correct regarding method overriding?(Choose 2) 
    • A. 

      Both the methods must not be in the same class

    • B. 

      Same name same signature

    • C. 

      Same name different signature

    • D. 

      Both the methods must be in the same class

  • 3. 
    Which of the following statement is true regarding method overloading?
    • A. 

      Static methods cannot be overloaded

    • B. 

      Overloaded methods should always return same type of value

    • C. 

      Overloaded methods cannot be declared as abstract

    • D. 

      Methods can be overloaded across inherited classes

  • 4. 
    Runtime exception can be handled.
    • A. 

      True

    • B. 

      False

  • 5. 
    Unboxing the Numeric Wrapper types to primitive types is done under operations. 
    • A. 

      ++

    • B. 

      +

    • C. 

      -

    • D. 

      =

    • E. 

      ==

  • 6. 
    Which of the following option is not a valid wrapper type object creation?
    • A. 

      New Boolean(“truth”);

    • B. 

      New Long(“3465”);

    • C. 

      New Integer(“637”);

    • D. 

      New Character(“B”);

    • E. 

      New Byte(“10”);

  • 7. 
    What will be the output of following code? Int a=2; Integer b=2; System.out.println(a==b);
    • A. 

      0

    • B. 

      Compile time error

    • C. 

      1

    • D. 

      Run time error

  • 8. 
    Which of the following correctly fits for the definition holding instances of other objects?
    • A. 

      Polymorphic

    • B. 

      Generic

    • C. 

      Composition

    • D. 

      Aggregation

  • 9. 
    Consider the following code: Class MyError extends Error{ } Public class TestError { Public static void main(String args[]) { Try { Test(); } catch(Error ie) { System.out.println(“Error caught”); } } Static void test() throws Error { Throw new MyError(); } } Which of the following option gives the output for the above code?
    • A. 

      Run time error test() method does not throw an error type instance

    • B. 

      Compile time error Cannot catch Error type objects

    • C. 

      Compile time error Error class cannot be extended

    • D. 

      Prints Error caught

  • 10. 
     Consider the following code: 01 import java.util.Set; 02 import java.util.TreeSet; 03 04 class TestSet{ 05 public static void main(String[] args) { 06 Set set = new TreeSet(); 07 set.add(“Green World”); 08 set.add(1); 09 set.add(“Green Peace”); 10 System.out.println(set); 11 } 12 } Which of the following option gives the output for the above code?
    • A. 

      Compilation error at line no 8

    • B. 

      Throws Runtime Exception

    • C. 

      Prints the output [Green World, 1, Green Peace] at line no 9

    • D. 

      Prints the output [Green World, Green Peace] at line no 9

  • 11. 
    Select the correct answer
    • A. 

      An interface can implement another interface

    • B. 

      An interface can be instantiated

    • C. 

      All the methods of an interface are by default abstract

    • D. 

      An interface can contain concrete methods

  • 12. 
    Which of the following statement is false about for-each loop in Java?
    • A. 

      For-each loop does the automatic typecasting

    • B. 

      For-each loop is an alternative to Enumeration

    • C. 

      For-each loop is an alternative to Iterator

    • D. 

      For-each loop can work only with generic collections

  • 13. 
    HashMap is a Collection class. 
    • A. 

      True

    • B. 

      False

  • 14. 
    Which of the following are true regarding RuntimeException? 
    • A. 

      RuntimeException can be handled using a catch that handles Error

    • B. 

      Any class that derives the RuntimeException will always be an unchecked exception

    • C. 

      RuntimeException does not require a throws declaration

    • D. 

      If RuntimeException is declared using throws clause, then the calling methods should handle it using try –catch block

  • 15. 
    Consider the following interface declaration: interface A{void main(String[] args);} interface B{public void main(String[] args);} interface C{public static void main(String[] args);}   interface D{protected void main(String[] args);} interface E{private void main(String[] args);} Which of the following option gives the valid interface declaration that will compile successfully?
    • A. 

      Interface A,B,C

    • B. 

      Interface B,C,D

    • C. 

      Interface B,C

    • D. 

      Interface A,B

  • 16. 
    Which of the following statements is TRUE about StringBuffer class?
    • A. 

      StringBuffer can be extended, since it is mutable

    • B. 

      StringBuffer is a mutable class

    • C. 

      StringBuffer is a sub class of String class

    • D. 

      StringBuffer is a Wrapper to the existing String class

  • 17. 
    Which of the following statements are true about finalize method?
    • A. 

      Finalize will run when an object becomes unreachable

    • B. 

      Finalize allows a programmer to free memory allocated to an object

    • C. 

      Finalize may run before or after an object is garbage collected

    • D. 

      Finalize will always run before an object is garbage collected

  • 18. 
    Which of the following statements are true regarding try-catch-finally?
    • A. 

      A catch block can have another try block nested inside

    • B. 

      An exception which is not handled by a catch block will be handled by subsequent catch blocks

    • C. 

      Finally block cannot have a try block with multiple catch blocks

    • D. 

      An exception which is not handled by a catch block can be handled by writing another try catch block inside finally block

  • 19. 
    Which of the following is true about packages?
    • A. 

      Class and Interfaces in the sub packages will be automatically available to the outer packages without using import statement.

    • B. 

      Packages can contain both Classes and Interfaces

    • C. 

      Packages can contain only Java Source files

    • D. 

      Sub packages should be declared as private in order to deny importing them

  • 20. 
    Consider the following Statements: Statement A: Anonymous inner class can extend a class and implement an interface at the same time . Statement B: Anonymous class can have their own members. Which of the following option is true regarding the above statements?
    • A. 

      Both the statements are true

    • B. 

      Statement B is true and A is false

    • C. 

      Both the statement are false

    • D. 

      Statement A is true and B is false

  • 21. 
    Which of the following option gives the valid collection implementation class that implements the List interface and also provides the additional methods to get, add and remove elements from the head and tail of the list without specifying an index?
    • A. 

      LinkedList

    • B. 

      ArrayList

    • C. 

      List

    • D. 

      Collection

  • 22. 
    Consider the following code: 1 public class FinallyCatch { 2 public static void main(String args[]) { 3 try { 4 throw new java.io.IOException(); 5 } 6 } 7 } Which of the following is true regarding the above code?
    • A. 

      Demands a finally block at line number 4

    • B. 

      Shows unhandled exception type IOException at line number 5

    • C. 

      Demands a finally block at line number 5

  • 23. 
    Consider the following code : class BigLength { public int getLength() {return 4;} } public class SmallLength extends BigLength { public long getLength() {return 5;} public static void main(String args[]) { BigLength s =new BigLength(); SmallLength sb=new SmallLength(); System.out.println(s.getLength()+”,”+sb.getLength() }; } } Which of the following option gives the valid output for the above code?
    • A. 

      4,5

    • B. 

      Compilation error

    • C. 

      4,4

    • D. 

      5,5

    • E. 

      5,4

  • 24. 
    Which of the following options are the methods NOT available in StringBuffer class? 
    • A. 

      Append(short s)

    • B. 

      Append(byte b)

    • C. 

      Append(int i)

    • D. 

      Append(boolean b)

    • E. 

      Append(long l)

  • 25. 
    Consider the following code: class Testone { public class Main { public static void main(String[] args) { int i=1; int n=++i%5; System.out.println(“value of n is:” +n); n=i--%4; System.out.println(“value of n is:” +n); n=i++%2; System.out.println(“value of n is:” +n); } } Which of the following option gives the output for the above code?
    • A. 

      1,2,2

    • B. 

      2,2,2

    • C. 

      0.2,0.5,0.5

    • D. 

      2,2,1