Hardest Java Exam Trivia Quiz!

20 Questions | Total Attempts: 4966

SettingsSettingsSettings
Hardest Java Exam Trivia Quiz! - Quiz

Are you a real programmer? Get ready to take the hardest Java exam trivia quiz that we have brought here for you. The quiz is on Java, and it is going to be very tough. If you know Java very well, only then will you be able to pass this test with a good score? Do you have the confidence? Let's see how well you perform in this amazing quiz.


Questions and Answers
  • 1. 
    Consider the following code and choose the correct option: class X {      int x;      X(int x){         x=2;     } } class Y extends X{      Y(){}      void displayX(){         System.out.print(x);     }     public static void main(String args[]){         new Y().displayX();     } }
    • A. 

      Compiles and display 2

    • B. 

      Compiles and runs without any output

    • C. 

      Compiles and display 0

    • D. 

      Compilation error

  • 2. 
    Consider the following code and choose the correct option: class Test{      private void display(){         System.out.println("Display()");}     private static void show() {          display();         System.out.println("show()");     }     public static void main(String arg[]){         show();     } }
    • A. 

      Compiles and prints show()

    • B. 

      Compiles and prints Display() show()

    • C. 

      Compiles but throws runtime exception

    • D. 

      Compilation error

  • 3. 
    Consider the following code and choose the correct option: class A{      A(){         System.out.print("From A");     } } class B extends A{      B(int z){         z=2;     }     public static void main(String args[]){         new B(3);     } }
    • A. 

      Compilation error

    • B. 

      Comiples and prints From A

    • C. 

      Compiles but throws runtime exception

    • D. 

      Compiles and display 3

  • 4. 
    Consider the following code and choose the correct option: class One{     int var1;     One (int x){         var1 = x;     } } class Derived extends One{     int var2;     Derived(){         super(1);     }     void display(){         System.out.println("var 1="+var1+", var 2="+var2);     } } class Main{     public static void main(String[] args){         Derived obj = new Derived();         obj.display();     } }
    • A. 

      Compiles successfully but runtime error

    • B. 

      Var 1=1 var 2=0

    • C. 

      Compile error

    • D. 

      Var 1=0 var 2=0

  • 5. 
    Consider the following code and choose the correct option: class Order{         Order(){             System.out.println("Cat");         }         public static void main(String... Args){             Order obj = new Order();             System.out.println("Ant");         }         static{             System.out.println("Dog");         }         {             System.out.println("Man");         }     }
    • A. 

      Compile error

    • B. 

      Man Dog Cat Ant

    • C. 

      Dog Man Cat Ant

    • D. 

      Cat Ant Dog Man

  • 6. 
    Consider the following code and choose the correct option: public class MyAr {     public static void main(String argv[]) {         MyAr m = new MyAr();         m.amethod();     }     public void amethod() {         final int i1;         System.out.println(i1);     } }
    • A. 

      Unresolved compilation problem: The local variable i1 may not have been initialized

    • B. 

      Compilation and output of null

    • C. 

      Compiled and output of 0

    • D. 

      None of the given options

  • 7. 
    What would be the output? class MyClass1 {   private int area(int side)    {            return(side * side);     }     public static void main(String args[ ])     {            MyClass1 MC = new MyClass1( );            int area = MC.area(50);            System.out.println(area);     }  }
    • A. 

      Compilation error

    • B. 

      Runtime Exception

    • C. 

      2500

    • D. 

      50

  • 8. 
    Consider the following code and choose the correct option: public class MyClass {  public static void main(String arguments[]) {   amethod(arguments);  }  public static void amethod(String[] arguments) {   System.out.println(arguments[0]);   System.out.println(arguments[1]);  } }
    • A. 

      Prints Hi Hello

    • B. 

      Compiler Error

    • C. 

      Runs but no output

    • D. 

      Runtime Error

  • 9. 
    Examine this code: String stringA = "Wild"; String stringB = " Irish"; String stringC = " Rose"; String result; Which of the following puts a reference to "Wild Irish Rose" in result?
    • A. 

      Result = stringA.concat( stringB.concat( stringC ) );

    • B. 

      Result.concat( stringA, stringB, stringC );

    • C. 

      Result+stringA+stringB+stringC;

    • D. 

      Result = concat(StringA).concat(StringB).concat(StringC)

  • 10. 
    Carefully read the question and answer accordingly. A class can be declared as _______ if you do not want the class to be subclasses. Using the __________keyword we can abstract a class from its implementation
    • A. 

      Protected, interface

    • B. 

      Final, interface

    • C. 

      Public, friend

    • D. 

      Final, protected

    • E. 

      Private, abstract

  • 11. 
    Consider the following code and choose the correct option: abstract class MineBase {     abstract void amethod();     static int i; } public class Mine extends MineBase {     public static void main(String argv[]){         int[] ar=new int[5];         for(i=0;i < ar.length;i++)             System.out.println(ar[i]);     } }
    • A. 

      A Sequence of 5 zero's will be printed like 0 0 0 0 0

    • B. 

      A Sequence of 5 one's will be printed like 1 1 1 1 1

    • C. 

      IndexOutOfBoundes Error

    • D. 

      Compilation Error occurs and to avoid them we need to declare Mine class as abstract

  • 12. 
    What will be the result when you attempt to compile this program?  public class Rand{     public static void main(String argv[]){         int iRand;         iRand = Math.random();         System.out.println(iRand);             } }
    • A. 

      Compile time error referring to a cast problem

    • B. 

      A random number between 1 and 10

    • C. 

      A random number between 0 and 1

    • D. 

      A compile time error as random being an undefined method

  • 13. 
    Which of the following declarations are correct? (Choose TWO)
    • A. 

      Boolean b = TRUE;

    • B. 

      Byte b = 256;

    • C. 

      String s = “null”;

    • D. 

      Int i = new Integer(“56”);

  • 14. 
    Class A, B and C are in multilevel inheritance hierarchy respectively. In the main method of some other class if class C object is created, in what sequence the three constructors execute?
    • A. 

      Constructor of A executes first, followed by the constructor of B and C

    • B. 

      Constructor of C executes first followed by the constructor of A and B

    • C. 

      Constructor of C executes first followed by the constructor of B and A

    • D. 

      Constructor of A executes first followed by the constructor of C and B

  • 15. 
    Examine this code: class Base{     Base(){         int i = 100;         System.out.println(i);     } } public class Pri extends Base{     static int i = 200;     public static void main(String argv[]){         new Base();         System.out.println(i);     } }
    • A. 

      100

    • B. 

      100 200

    • C. 

      200

    • D. 

      Compile time error

  • 16. 
    Given, public class Q {     public static void main(String argv[]) {         int anar[] = new int[] { 1, 2, 3 };         System.out.println(anar[1]);     } }
    • A. 

      Compiler Error: anar is referenced before it is initialized

    • B. 

      2

    • C. 

      1

    • D. 

      Compiler Error: size of array must be defined

  • 17. 
    Which statements, when inserted at (1), will not result in compile-time errors? [Choose Three] public class ThisUsage {     int planets;     static int suns;     public void gaze() {         int i;         // (1) INSERT STATEMENT HERE     } }
    • A. 

      I = this.planets;

    • B. 

      I = this.suns;

    • C. 

      This = new ThisUsage();

    • D. 

      This.i = 4;

    • E. 

      This.suns = planets;

  • 18. 
    Given the following code what will be output?  public class Pass{     static int j=20;     public static void main(String argv[]){         int i=10;         Pass p = new Pass();         p.amethod(i);         System.out.println(i);         System.out.println(j);     }     public void amethod(int i) {         j+=(i+i);     } }
    • A. 

      Error: amethod parameter does not match variable

    • B. 

      10 and 40

    • C. 

      10, and 20

    • D. 

      20 and 40

  • 19. 
    Given, public class c123 {  private c123() {   System.out.println("Hellow");  }  public static void main(String args[]) {   c123 o1 = new c123();   c213 o2 = new c213();  } } class c213 {  private c213() {   System.out.println("Hello123");  } }
    • A. 

      Hellow

    • B. 

      It is not possible to declare a constructor as private

    • C. 

      Compilation Error

    • D. 

      Runs without any output

  • 20. 
    Here is the general syntax for method definition: accessModifier returnType methodName( parameterList ) {   Java statements   return returnValue; } What is true for the returnType and the returnValue?
    • A. 

      The returnValue can be any type, but will be automatically converted to returnType when the method returns to the caller

    • B. 

      If the returnType is void then the returnValue can be any type

    • C. 

      The returnValue must be the same type as the returnType, or be of a type that can be converted to returnType without loss of information

    • D. 

      The returnValue must be exactly the same type as the returnType.

Back to Top Back to top