Core Java Hardest Test: Trivia Quiz!

40 Questions | Total Attempts: 104

SettingsSettingsSettings
Core Java Hardest Test: Trivia Quiz! - Quiz

Do you know the core Java language? Java is a classed based language that was made to have minimum implementation dependencies. It is a general-purpose programming language that allows application developers to run anywhere. Java works on different platforms such as Windows, Mac, Linux, and Raspberry Pi. It is relatively easy to learn and simple to use. This quiz is the most challenging core Java quiz, but you can do it. Go for it.


Questions and Answers
  • 1. 
    Choose the possible constructor arguments of the Float wrapper class.
    • A. 

      Float

    • B. 

      Double

    • C. 

      String

    • D. 

      Int

    • E. 

      Byte

  • 2. 
    Integer y = 567;   Integer x = y;   System.out.println(y==x);  y++; System.out.println(x + " " + y); System.out.println(y==x);
    • A. 

      False 568 567 true

    • B. 

      True 567 566 false

    • C. 

      True 567 568 false

    • D. 

      False 567 568 true

  • 3. 
    Class Boxing2 { static Integer x; public static void main(String [] args) { doStuff(x); } static void doStuff(int z) { int z2 = 5; System.out.println(z2 + z); } } From the above code, Will it throws a NullPointerException?
    • A. 

      True

    • B. 

      False

  • 4. 
    Class EasyOver { static void go(int x) { System.out.print("int "); } static void go(long x) { System.out.print("long "); } static void go(double x) { System.out.print("double "); } public static void main(String [] args) { byte b = 5; short s = 5; long l = 5; float f = 5.0f; go(b); go(s); go(l); go(f); } } Predict the output of the above code.  
    • A. 

      Int double long int

    • B. 

      Long int double int

    • C. 

      Double int int long

    • D. 

      Int int long double

  • 5. 
    Class AddBoxing { static void go(Integer x) { System.out.println("Integer"); } static void go(long x) { System.out.println("long"); } public static void main(String [] args) { int i = 5; go(i);  } } Which go() will be invoked? (choose 1)  
    • A. 

      Long and Integer

    • B. 

      Integer

    • C. 

      Long

    • D. 

      None of the above

  • 6. 
    Class BoxAndWiden { static void go(Object o) { Byte b2 = (Byte) o; System.out.println(b2); } public static void main(String [] args) { byte b = 5; go(b); } } What will be the output of above program?  
    • A. 

      0

    • B. 

      5

    • C. 

      Returns garbage value

    • D. 

      Compiler error

  • 7. 
     public class Test {   public static void main(String[] args) { Integer in = 1;   int i = 1;  System.out.print(in.equals(i));   System.out.print(in == i);  }} What will be the result of above code ?
    • A. 

      False false

    • B. 

      True true

    • C. 

      False true

    • D. 

      True false

  • 8. 
     public class Test {     public static void main(String[] args) {     Number i=10;     int j = 10;     if (i.equals(j))     {     System.out.println("equals");     }     else   System.out.println("not equals"); } } what will be the result of above code?  
    • A. 

      Not equal

    • B. 

      Equal

    • C. 

      Compile time error at line 3

    • D. 

      Compile time error at line 5

  • 9. 
    Examine: 1   public class Test3 {   2    static void pass(int i) {     }   3    static void pass(Integer i) { 4    System.out.println(i);     }   5    public static void main(String[] args) { 6    pass(1);     }     } What will be the result of above code ?  
    • A. 

      1

    • B. 

      Compile time error at line no 2.

    • C. 

      Print nothing

    • D. 

      Compile time error at line no 6.

  • 10. 
    1    public class Test2 { 2    public static void main(String[] args) { 3    int i = 1; 4    Integer I = new Integer(i); 5    method(i); 6    method(I); 7    }   8    static void method(Integer I) { 9    System.out.print(" Wrapper"); 10   }   11    static void method(int i) { 12    System.out.print(" Primitive"); }} What will be the result of above code ?  
    • A. 

      Primitive Wrapper

    • B. 

      Wrapper

    • C. 

      Primitive

    • D. 

      Wrapper Primitive

  • 11. 
    1. public class Test {  2. public static void main(String [ ] args) {  3. 4. switch(a) {  5. default:  6. System.out.println("You choose correct option");  7. } } } Which given below snippet is best for inserting at line number 3 to compile the above code successfully. (choose 3)  
    • A. 

      Int a = 3;

    • B. 

      Short a = 4;

    • C. 

      Char a = 'p';

    • D. 

      Long a= 388;

    • E. 

      Boolean a = true;

  • 12. 
    1 .public class LoopOutput{ 2. public static void main(String args[]) { 3. int a = 4; 4. int b = 3; 5. int c = 2; 6. for(;b < 7;b++) { 7. if(c++ > a) { 8. a = b + c; 9. } 11. } 12. System.out.println("Value of C is " + c); 13. } 14. } What is the output of variable "c" after completion of for loop :
    • A. 

      1

    • B. 

      4

    • C. 

      6

    • D. 

      8

  • 13. 
    1 .public class Question3{ 2 .public static void main(String[] args) { 3 .try { 4 .int a= (int)(Math.random()*5); 5 .if(a<=2.5) 6 .System.out.println("a="+a); 7 .else 8 .throw new Exception("a>2.5"); 9. } catch (Exception e){   10. System.err.println(e.getMessage() ); 11. System.err.println("Value of a="+a); 12. } } } Find the output of the following code :  
    • A. 

      An Exception is raised during compilation

    • B. 

      An Exception is thrown at run time

    • C. 

      Unresolved compilation problem

    • D. 

      A=2 or a=1 or i >2.5 Value of i =null

  • 14. 
    1.  import java.io.*; 2.  public class Example4 { 3.  public static void main(String[] args) { 4.  Example4 e4 = new Example4(); 5.  try{ 6.  e4.check();} 7.  catch(IOException e){}} 8.  void check() throws IOException{ 9.  System.out.println("Inside check() method of Class "); 10. throw new IOException();}} 11. class Subexample4 extends Example4 { 12. void check() { 13. System.out.println("Inside check() Method of Subclass"); 14. }} What will be the output of the following code snippet  :  
    • A. 

      Above program will throw exception & will not run

    • B. 

      Inside check() method of class

    • C. 

      Inside check() method of Subclass

  • 15. 
    What should be at line number 3 to get the total sum of array "sum" ? public int totalsum( int[] sum ){ int a, b= 0 ; //which 'for' loop should be here(line :3)  {  b += sum[ a++ ] ; } return b ; } Which 'for' loop should be at line number 3 to calculate total sum of the array "sum" :
    • A. 

      for( int a = 0 ; a< sum.length ; )

    • B. 

      For( a= 0 ; a< sum.length ; )

    • C. 

      For( a = 0 ; a< sum.length ; a++ )

    • D. 

      for( a = 1 ; i

  • 16. 
    Which modifier should  used in place of  **** , so that it's subclass saved in other package can access " FixVariable() " method of it's super class ?   package NewPackage; public class Example extends rose{ private int length; *** void FixVariable( int a ) { length = a; } }     // subclass in different package     import NewPackage.Example ; public class SubExample extends Example { SubExample() { FixVariable( 201 ); }
    • A. 

      Private and protected

    • B. 

      Public and protected

    • C. 

      Protected

    • D. 

      Default(blank)

  • 17. 
    Public class Example6{ public static void main(String args[]) { public int check(char a) { if (a <= 'N') { if (a == 'E') return 2; return 1; } else if (a == 'S') return 3; else if (a == 'W') return 4; return 0; } } } Which are correct input-output options : (choose 2)
    • A. 

      A='A' output=1.

    • B. 

      Compile error.

    • C. 

      A='X' output=0.

    • D. 

      A='D' output=0.

  • 18. 
    What is the output of the following 'for' loop code :   public class Example12 { public static void main(String[] args) { int a, b; flag: for (a = 0; a < 6; a++) { for (b = 5; b > 2; b--) { if (a == b) { System.out.print(" " + b); continue flag; } } }   } }}  
    • A. 

      5

    • B. 

      Compile error

    • C. 

      5 4

    • D. 

      5 4 3

  • 19. 
    What would be the output after executing following code :   public class Example13 { public static void main(String[] args) throws Exception { int a = 30; while (a) { System.out.print("value:" + a--); } } }  
    • A. 

      Compile error

    • B. 

      30 29,.....untill 1

    • C. 

      1 2 3.....untill 30

    • D. 

      No output

  • 20. 
    Find the Output of the following code :   public class Example15 { public static void main(String[] args) { for (int a = 0; a < 10; ++a) { try { if (a % 3 == 0) throw new Exception("Except1"); try { if (a % 3 == 1) throw new Exception("Except2"); System.out.println(a); } catch (Exception inside) { a *= 2; } finally { ++a; } } catch (Exception outside) { a += 3; } finally { ++a; } } } }  
    • A. 

      5 8

    • B. 

      5

    • C. 

      8

    • D. 

      Compile error

  • 21. 
    Given a sample code:   1 public class Sample { 2 public static void main(String args[]) {  3 int k=1, m=3; 4 do { 5 k=++k; 6 m--; 7 } while(m>0); 8 System.out.println(k); 9 }}   What will be the result of above code ?  
    • A. 

      1

    • B. 

      2

    • C. 

      4

    • D. 

      The program compilation fails because of line number 5.

  • 22. 
    Given a sample code:   1    public class Sample{ 2    public static void main(String args[]) { 3    int i = 1, j = 2; 4    i++; 5    j--; 6    if (i / j > 1) 7    i++; 8    System.out.println(i + j); }}   What will be the result of above code ?  
    • A. 

      1

    • B. 

      2

    • C. 

      4

    • D. 

      The program compilation fails because of line number 6.

  • 23. 
    Given a sample code: 1    public class Sample { 2    public static void main(String args[]) { 3    int i = 1, j = 2; 4    i++; 5    j--; 6    if (i % j > 1) 7    i++; 8    System.out.println("i = "+i+ " j = "+j); }} What will be the result of above code ?
    • A. 

      i = 2 j = 1

    • B. 

      i = 1 j = 2

    • C. 

      i = 2 j = 2

    • D. 

      The program compilation fails because of line number 6.

  • 24. 
    Given a sample code: 1    public class Test { 2    public static void main(String args[]) {  3    int i = 5; 4    do { 5    i--; 6    } while (i > 2); 7    System.out.println(i); 8    }} What will be the result of above code ?
    • A. 

      1

    • B. 

      2

    • C. 

      4

    • D. 

      The program compilation fails because of line number 6.

  • 25. 
    Given a sample code: 1    public class Test { 2    public static void main(String args[]) {  3    int j; 4    do { 5    j++; 6       } 7    while(j < 0); 8    System.out.println(j); }} What will be the result of above code ?
    • A. 

      The program compilation fails because of line number 3.

    • B. 

      1

    • C. 

      3

    • D. 

      The program compilation fails because of line number 5.

Back to Top Back to top