Java - Quiz

30 Questions
Java Quizzes & Trivia

Test your Java Skills.

Please wait...
Questions and Answers
  • 1. 
    What is the size of a Char?
    • A. 

      4 bits

    • B. 

      7 bits

    • C. 

      8 bits

    • D. 

      16 bits

  • 2. 
     A class cannot be declared
    • A. 

      Static

    • B. 

      Private

  • 3. 
    Following code will result in: int a = 3.5;
    • A. 

      Compilation error

    • B. 

      Runtime error

  • 4. 
    Following code will result in: int a1 = 5; double a2 = (float)a1;
    • A. 

      Runtime error

    • B. 

      No errors

  • 5. 
     Following code will result in: int a = 9/0;
    • A. 

      Compilation error: Divisions must be in a try block.

    • B. 

      Runtime Exception

  • 6. 
    Following code will result in: float a = 9/0
    • A. 

      Compilation error: DivideByZeroException

    • B. 

      Runtime Exception

  • 7. 
    A class can be transient
    • A. 

      True

    • B. 

      False

  • 8. 
    Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); }}
    • A. 

      Compilation error

    • B. 

      Runtime Error

  • 9. 
    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}
    • A. 

      Compile error

    • B. 

      No error

  • 10. 
    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}
    • A. 

      Runtime Exception

    • B. 

      No errors

  • 11. 
    Methods that are marked protected can be called in any subclass of that class.
    • A. 

      True

    • B. 

      False

  • 12. 
    An abstract class can have non-abstract methods
    • A. 

      True

    • B. 

      False

  • 13. 
    Java keywords are written in lowercase as well as uppercase
    • A. 

      True

    • B. 

      False

  • 14. 
    What is an instanceof
    • A. 

      A methods in object

    • B. 

      An operator and keyword

  • 15. 
    Primitive datatypes are allocated on a stack
    • A. 

      True

    • B. 

      False

  • 16. 
    Can you compare a boolean to an integer?
    • A. 

      Yes

    • B. 

      No

  • 17. 
    If class A implements an interface does it need to implement all methods of that interface?
    • A. 

      Yes, always

    • B. 

      No, not when A is abstract

  • 18. 
    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?
    • A. 

      True

    • B. 

      FALSE

  • 19. 
    The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.
    • A. 

      True

    • B. 

      False

  • 20. 
    Inner classes can be defined within methods
    • A. 

      True

    • B. 

      False

  • 21. 
    Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.
    • A. 

      True

    • B. 

      False

  • 22. 
    The default statement of a switch is always executed
    • A. 

      True

    • B. 

      False

  • 23. 
    How can you prevent a member variable from becoming serialized?
    • A. 

      By marking it volatile

    • B. 

      By marking it transient

  • 24. 
    What is Java (in regard to Computer Science) ?
    • A. 

       A type of coffee

    • B. 

      AN OBJECT-ORIENTED PROGRAMMING LANGUAGE

  • 25. 
    WHAT IS AN APPLET?
    • A. 

      A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER

    • B. 

       A type of coffee

  • 26. 
    Java runs on _______.
    • A. 

       Windows

    • B. 

      All of the Above

    • C. 

       Unix/Linux

  • 27. 
    Why can't the whole program just consist of the one line that does the painting ?
    • A. 

      In Java, to create an applet, you can't call on functions without defining a class to call them.

    • B. 

      The drawString function is not defined without the "import" statements at the top.

    • C. 

       All of the above.

  • 28. 
    What's the difference between an Applet and an application ?
    • A. 

      Applets can paint words, applications cannot.

    • B. 

       Applets are run over the web.

  • 29. 
    What is the main function of any variable ?
    • A. 

       To add numbers together

    • B. 

       To keep track of data in the memory of the computer

  • 30. 
    What is the proper way to declare a variable ?
    • A. 

      VariableName variableType;

    • B. 

      VariableType variableName;