Java Programming Test! Hardest Trivia Questions Quiz

5 Questions | Total Attempts: 123

SettingsSettingsSettings
Java Programming Test! Hardest Trivia Questions Quiz - Quiz

Below is what is seen by many as the hardest trivia questions java programming test. It is not designed for beginners when it comes to this course but for the professionals who think they understand this programming language and how to use it. How about you give it a shot and get to see if you are a novice or an accrual pro when it comes to all things java.


Questions and Answers
  • 1. 
    Given: public class Test{ public static void main(String[] args) { Test obj = new Test(); short letter = 97; int letter2 = 98; int long = 99; System.out.print((char) letter + " "); System.out.print((char) letter2); } } What is the result?
    • A. 

      A b

    • B. 

      A followed by an exception

    • C. 

      Compilation fails.

    • D. 

      A ClassCastException is thrown at runtime.

  • 2. 
    Given the code fragment:  public static void main(String[] args) { short s1 = 200; int s2 = 400; long s3 = (long) s1 + s2; // line n1 String s4 = (String) (s3 * s2 ); // line n2 System.out.println("Sum is " + s4); } What is the result?
    • A. 

      Sum is 600

    • B. 

      Compilation fails at line n1.

    • C. 

      Compilation fails at line n2.

    • D. 

      A exception is thrown at line n1.

    • E. 

      A exception is thrown at line n2.

  • 3. 
    Given: public class Test{ public static void main(String[] args) { short letter; int letter2 = letter + 2; // line n1 System.out.print((short) letter2); // line n2 } } What is the result?
    • A. 

      Compilation fails at line n1.

    • B. 

      Compilation fails at line n2.

    • C. 

      A exception is thrown at line n1.

    • D. 

      A exception is thrown at line n2.

  • 4. 
    Given the code fragment: public static void main(String[] args) { int a = 10; float b = 10.25f; double c = 100; a = b; // line 7 b = a; // line 8 c = b; // line 9 c = a; // line 10 } Which change enables the code fragment to compile successfully?
    • A. 

      Replace line 10 with c = (double) a;

    • B. 

      Replace line 8 with b = (float) a;

    • C. 

      Replace line 7 with a = (int) b;

    • D. 

      Replace line 9 with c = (double) b;

  • 5. 
    Given: public class Test{ public static void main(String[] args) { Test obj = new Test(); short letter = 97; int letter2 = 98; System.out.print((char) letter + " "); System.out.print((char) letter2); } } What is the result?
    • A. 

      A b

    • B. 

      A followed by an exception

    • C. 

      Compilation fails

    • D. 

      A ClassCastException is thrown at runtime.

Back to Top Back to top