Java - Quiz

42 Questions | Attempts: 300
Share

SettingsSettingsSettings
Java Quizzes & Trivia

Test your Java Skills.


Questions and Answers
  • 1. 

    What is the size of a Char?

    • A.

      4 bits

    • B.

      7 bits

    • C.

      8 bits

    • D.

      16 bits

    Correct Answer
    D. 16 bits
  • 2. 

     A class cannot be declared

    • A.

      Static

    • B.

      Private

    Correct Answer
    B. Private
  • 3. 

    Following code will result in: int a = 3.5;

    • A.

      Compilation error

    • B.

      Runtime error

    Correct Answer
    A. Compilation error
  • 4. 

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

    • A.

      Runtime error

    • B.

      No errors

    Correct Answer
    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

    Correct Answer
    B. Runtime Exception
  • 6. 

    Following code will result in: float a = 9/0

    • A.

      Compilation error: DivideByZeroException

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
  • 7. 

    A class can be transient

    • A.

      True

    • B.

      False

    Correct Answer
    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

    Correct Answer
    A. Compilation 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

    Correct Answer
    A. Compile 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

    Correct Answer
    B. No errors
  • 11. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 12. 

    An abstract class can have non-abstract methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 13. 

    Java keywords are written in lowercase as well as uppercase

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 14. 

    What is an instanceof

    • A.

      A methods in object

    • B.

      An operator and keyword

    Correct Answer
    B. An operator and keyword
  • 15. 

    Primitive datatypes are allocated on a stack

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 16. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    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

    Correct Answer
    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

    Correct Answer
    B. FALSE
  • 19. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 20. 

    Inner classes can be defined within methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 21. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 22. 

    The default statement of a switch is always executed

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 23. 

    How can you prevent a member variable from becoming serialized?

    • A.

      By marking it volatile

    • B.

      By marking it transient

    Correct Answer
    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

    Correct Answer
    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

    Correct Answer
    A. A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER
  • 26. 

    Java runs on _______.

    • A.

       Windows

    • B.

      All of the Above

    • C.

       Unix/Linux

    Correct Answer
    B. All of the Above
  • 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.

    Correct Answer
    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.

    Correct Answer
    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

    Correct Answer
    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;

    Correct Answer
    B. VariableType variableName;
  • 31. 

     Booleans are _______.

    • A.

       True or False

    • B.

       Single characters

    Correct Answer
    A.  True or False
  • 32. 

    The following statements make “length” be what number ?

    • A.

       5

    • B.

      6

    Correct Answer
    A.  5
  • 33. 

    What is an assignment statement ?

    • A.

      Assigning a name to a variable

    • B.

      Assigning a value to a variable

    Correct Answer
    B. Assigning a value to a variable
  • 34. 

    What will be the value of “num” after the following statements?

    • A.

      1

    • B.

      12

    Correct Answer
    B. 12
  • 35. 

     If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

    • A.

      &&

    • B.

      !!

    Correct Answer
    A. &&
  • 36. 

    Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

    • A.

       if ((x < 3) || (y > = 4))

    • B.

       if ((x > 3) || (y < = 4))

    Correct Answer
    A.  if ((x < 3) || (y > = 4))
  • 37. 

     What is a loop ?

    • A.

       A new type of Applet

    • B.

       A segment of code to be run a specified amount of times

    Correct Answer
    B.  A segment of code to be run a specified amount of times
  • 38. 

    What is essential in making sure that your loop is not infinite ?

    • A.

      That there is a Boolean statement somewhere in your code

    • B.

      That your Boolean statement will at some point be false

    Correct Answer
    B. That your Boolean statement will at some point be false
  • 39. 

    Which is NOT a section of all types of loops ?

    • A.

       Test statement

    • B.

       The word "while"

    Correct Answer
    B.  The word "while"
  • 40. 

    In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

    • A.

       Loop Body

    • B.

       Initialization

    Correct Answer
    A.  Loop Body
  • 41. 

    What is a function in terms of Computer Science ?

    • A.

       A group of code lines that performs a specific task

    • B.

       Something that contains an ‘init’

    Correct Answer
    A.  A group of code lines that performs a specific task
  • 42. 

    What does AWT stands for ?

    • A.

       Abstract window Toolkit

    • B.

       Adjust Window Toolkit

    Correct Answer
    A.  Abstract window Toolkit

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 14, 2014
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 24, 2013
    Quiz Created by
    Dbhacker9988
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.