Java Quiz For Beginners

93 Questions  I  By Xooxa
Please take the quiz to rate it.

 Java Quiz For Beginners
It is created for Beginners in Java. This is to test the knowledge of any Java Developer wannabe.

  
Changes are done, please start the quiz.


Questions and Answers

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
  • 1. 
    Object-Oriented Programming means ...  
    • A. 

      Being objective about what you develop

    • B. 

      Designing the application based on the objects discovered when analysing the problem

    • C. 

      Writing an algorithm before writing your program and having a test plan

    • D. 

      Writing a program composed of Java classes


  • 2. 
    If none of the private/protected/public is specified for a member, that member ...
    • A. 

      Is accessible publicly

    • B. 

      Is only accessible by other classes of the same package

    • C. 

      Is only accessible from within the class

    • D. 

      Is accessible by the class and its subclasses


  • 3. 
    Which one is not correct?
    • A. 

      A class needs to be instantiated as an object before being used

    • B. 

      An objects exists in memory in run time

    • C. 

      Class and object are just different names for the same thing

    • D. 

      An object is a variable, where its type is the class used to declare the variable


  • 4. 
    Which is not a part of defining an object?
    • A. 

      Description

    • B. 

      Methods

    • C. 

      Associations with other objects

    • D. 

      Name


  • 5. 
    Class B inherits from Class A, what cannot be said:
    • A. 

      B is a sub-class of A

    • B. 

      A is a super-class of B

    • C. 

      B has access to private members of A

    • D. 

      B has access to protected members of A


  • 6. 
    What is a member of a class
    • A. 

      An attribute

    • B. 

      A method

    • C. 

      Attribute or method

    • D. 

      A sub-class


  • 7. 
    A UML association from class A to class B means
    • A. 

      Class B inherits from Class A

    • B. 

      Class B is defined within class A

    • C. 

      Class B has an attribute of type A

    • D. 

      Class A has an attribute of type B


  • 8. 
    A UML association is ...
    • A. 

      Implemented as a Java attribute member

    • B. 

      Implemented as a Java method

    • C. 

      Implemented as a sub-class

    • D. 

      Implemented as a String constructor returning the name of the association target


  • 9. 
    An object could be ...
    • A. 

      Anything

    • B. 

      An algorithm

    • C. 

      A data container

    • D. 

      A program


  • 10. 
    A class is...
    • A. 

      An object

    • B. 

      An executable piece of code

    • C. 

      An abstract definition of an object

    • D. 

      A varibale


  • 11. 
    The size of a frame is set using ...
    • A. 

      The method setSize()

    • B. 

      Automtically in run-time

    • C. 

      The width and height attributes of the class JFrame

    • D. 

      WIDTH and HEIGHT properties of the window menu in Eclipse


  • 12. 
    Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?
    • A. 

      Javax.swing

    • B. 

      Javax.gui

    • C. 

      Java.awt

    • D. 

      Java.swing


  • 13. 
    Which one needs a web page to run
    • A. 

      A Java Application

    • B. 

      A Java Stand-Alone Application

    • C. 

      A Java Applet

    • D. 

      A Java Class


  • 14. 
    What does GUI stand for?
    • A. 

      Graphical User Interface

    • B. 

      Gimme Ur Internet

    • C. 

      Grand User Interface

    • D. 

      Graphical Useful Interface


  • 15. 
    How is the layout of widgets on a panel specified?
    • A. 

      Automatically

    • B. 

      By inheriting from the main container such as a JFrame or JApplet

    • C. 

      By calling the method setLayout

    • D. 

      By calling the method setContentPane


  • 16. 
    Which one adds the widget mainPanel to a frame in the constructor of the frame?
    • A. 

      Add(this.mainPanel);

    • B. 

      This.add(mainPanel);

    • C. 

      MainPanel.setVisible(true);

    • D. 

      GetContentPane().add(mainPanel);


  • 17. 
    Which one could be used as the main container in a Java application?
    • A. 

      JApplet

    • B. 

      JFrame

    • C. 

      JPanel

    • D. 

      JButton


  • 18. 
    How to define a JButton with the caption test?
    • A. 

      JButton aButton('test ');

    • B. 

      JButton aButton=new JButton("test");

    • C. 

      JButton aButton=new JButton(' test');

    • D. 

      JButton("test") aButton;


  • 19. 
    Which one adds the widget mainPanel to an applet in the init method of the applet?
    • A. 

      Add(mainPanel);

    • B. 

      This.add(mainPanel);

    • C. 

      MainPanel.setVisible(true);

    • D. 

      GetContentPane().add(mainPanel);


  • 20. 
    The size of an applet is set using ...
    • A. 

      The method setSize()

    • B. 

      Automtically in browser

    • C. 

      The width and height attributes of the class JApplet

    • D. 

      HTML properties WIDTH and HEIGHT of the APPLET tag.


  • 21. 
    The last value in an array called ar can be found at index:
    • A. 

      0

    • B. 

      1

    • C. 

      Ar.length

    • D. 

      Ar.length - 1


  • 22. 
    What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));
    • A. 

      6

    • B. 

      2+4

    • C. 

      1+3

    • D. 

      4


  • 23. 
    What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};
    • A. 

      For (int i =0; i < 3; i++) System.out.println( nums[i]);

    • B. 

      For (i = 1; i <= 3; i++) System.out.println(nums[i]);

    • C. 

      For (i = 0; i <= 3; i++) System.out.println(nums[i]);

    • D. 

      For (i = 1; i < 3; i++) System.out.println(nums[i]);


  • 24. 
    What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);
    • A. 

      Ab

    • B. 

      Ac

    • C. 

      Ace

    • D. 

      Bd


  • 25. 
    Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[3]?
    • A. 

      2

    • B. 

      3

    • C. 

      4

    • D. 

      5


  • 26. 
    Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[4]?
    • A. 

      2

    • B. 

      3

    • C. 

      4

    • D. 

      5


  • 27. 
    Given the declaration int [ ] nums = {8, 12, 23, 4, 15}, what expression will display the first element in the array (ie the number 8)
    • A. 

      System.out.print("The number is : " + nums[0]);

    • B. 

      System.out.print("The number is : " + nums[1]);

    • C. 

      System.out.print("The number is : " + nums[8]);

    • D. 

      System.out.print("The number is : " + nums);


  • 28. 
    An array holds:
    • A. 

      Similar values of same data type

    • B. 

      Different values of same data type

    • C. 

      Same values of different data types

    • D. 

      Different values of different data types


  • 29. 
    The range of indices for an array always start at:
    • A. 

      Whatever programmer specifies

    • B. 

      1

    • C. 

      0

    • D. 

      Size of array


  • 30. 
    The most common use of an array is to:
    • A. 

      Perform for loop on array

    • B. 

      Perform different operations on each element in array

    • C. 

      Perform the same operation on all elements in array

    • D. 

      Perform while loop on array


  • 31. 
    If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
    • A. 

      0

    • B. 

      5

    • C. 

      6

    • D. 

      7


  • 32. 
    The following prototype shows that a Cylinder subclass is derived from a superclass called Circle
    • A. 

      Class Circle extends Cylinder

    • B. 

      Class Cylinder derived Circle

    • C. 

      Class Cylinder extends Circle

    • D. 

      Class Circle derived Cylinder


  • 33. 
    We have three classes: ATM, ATM Display and Account. The ATM has one ATM Display and works by calling methods on class Account. Which will be shown as an association in UML?
    • A. 

      ATM version number

    • B. 

      The relationship from ATM to ATM Display

    • C. 

      The relationship from ATM to Account

    • D. 

      The account number


  • 34. 
    With inheritance, a derived subclass object can directly access any
    • A. 

      Public or private superclass member

    • B. 

      Private superclass member

    • C. 

      Public superclass member (and protected subclass members if it's in the samepackage)

    • D. 

      Protected, public or private superclass member


  • 35. 
    If classes Student, Staff and Faculty extend class Person, which one makes sense:
    • A. 

      Faculty[] faculties={new Person(), new Staff(), new Student()};

    • B. 

      Staff[] staff={new Person(), new Faculty(), new Student()};

    • C. 

      Person[] persons={new Faculty(), new Staff(), new Student()};


  • 36. 
    Choose the best definition for a Class.    
    • A. 

      A group of students in a class

    • B. 

      An object definition, containing the data and function elements necessary to create an object

    • C. 

      An action for a program


  • 37. 
    Choose the best definition of an object
    • A. 

      A thing

    • B. 

      An instance of a class

    • C. 

      Something you wear


  • 38. 
    Choose the appropriate data type for this value: "volatile"    
    • A. 

      Int

    • B. 

      String

    • C. 

      Double

    • D. 

      Boolean


  • 39. 
    Choose the appropriate data type for this value: true    
    • A. 

      Int

    • B. 

      Double

    • C. 

      String

    • D. 

      Boolean


  • 40. 
    Choose the appropriate data type for this value: 1
    • A. 

      Int

    • B. 

      Double

    • C. 

      String

    • D. 

      Boolean


  • 41. 
    Choose the appropriate data type for this value: 5.5    
    • A. 

      Int

    • B. 

      Double

    • C. 

      Boolean

    • D. 

      String


  • 42. 
    Choose the appropriate data type for this value: A    
    • A. 

      Int

    • B. 

      Double

    • C. 

      Char

    • D. 

      String


  • 43. 
    Choose the appropriate data type for this value: "1"    
    • A. 

      String

    • B. 

      Boolean

    • C. 

      Int

    • D. 

      Char


  • 44. 
    Choose the appropriate data type for this value: female    
    • A. 

      Boolean

    • B. 

      Int

    • C. 

      Char

    • D. 

      Double


  • 45. 
    Choose the appropriate data type for this field: kindOfBird    
    • A. 

      String

    • B. 

      Int

    • C. 

      Char

    • D. 

      Double


  • 46. 
    Choose the appropriate data type for this field: numberOfEggs    
    • A. 

      Double

    • B. 

      Char

    • C. 

      Boolean

    • D. 

      Int


  • 47. 
    Choose the appropriate data type for this field: weightInKilos    
    • A. 

      Char

    • B. 

      String

    • C. 

      Double

    • D. 

      Boolean


  • 48. 
    Choose the appropriate data type for this field: isSwimmer    
    • A. 

      Double

    • B. 

      Boolean

    • C. 

      String

    • D. 

      Int


  • 49. 
    Which of the following always need a Capital letter ?    
    • A. 

      Class names and Strings

    • B. 

      Objects and class names

    • C. 

      Fields and Strings

    • D. 

      Data types and fields


  • 50. 
    What is the role of the constructor? 
    • A. 

      Create an instance of a class (an object)

    • B. 

      Create names for methods

    • C. 

      To create some type of change in the state of an object


  • 51. 
    What is the size of a Char in Java?
    • A. 

      4 bits

    • B. 

      7 bits

    • C. 

      8 bits

    • D. 

      16 bits


  • 52. 
    A class cannot be declared:
    • A. 

      Static

    • B. 

      Private

    • C. 

      Default


  • 53. 
    Following code will result in: int num = 6.7;
    • A. 

      Compilation error

    • B. 

      Runtime error

    • C. 

      Num being 6.7

    • D. 

      Num being 6


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

      Compilation error

    • B. 

      Runtime error

    • C. 

      No errors

    • D. 

      Runtime Exception


  • 55. 
    Following code will result in: int num = 8/0;
    • A. 

      Compilation error: Divisions must be in a try block

    • B. 

      Compilation error: DivideByZeroException

    • C. 

      Runtime Exception

    • D. 

      No Error: a is NaN


  • 56. 
    Following code will result in: float num = 5/0;
    • A. 

      Compilation error: Divisions must be in a try block

    • B. 

      Compilation error: DivideByZeroException

    • C. 

      Runtime Exception

    • D. 

      No Error: a is NaN


  • 57. 
    A class can be transient
    • A. 

      True

    • B. 

      False


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

      Compilation error

    • B. 

      Runtime Error

    • C. 

      Runtime Exception

    • D. 

      Output of x is 1


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

      Compile error

    • B. 

      Runtime Exception

    • C. 

      No error

    • D. 

      No Output


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

      Compiler error

    • B. 

      Runtime Exception

    • C. 

      No errors

    • D. 

      Output is B


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

      True

    • B. 

      False


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

      True

    • B. 

      False


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

      True

    • B. 

      False


  • 64. 
    What is an instanceof?
    • A. 

      A methods in object

    • B. 

      An operator and keyword

    • C. 

      An operator only

    • D. 

      A keyword only


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

      True

    • B. 

      False


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

      Yes

    • B. 

      No


  • 67. 
    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


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

      Compiler error

    • B. 

      Runtime Exception

    • C. 

      True

    • D. 

      False


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

      True

    • B. 

      False


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

      True

    • B. 

      False


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

      True

    • B. 

      False


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

      True

    • B. 

      False


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

      By marking it private

    • B. 

      By marking it volatile

    • C. 

      By marking it transient

    • D. 

      You can not.


  • 74. 
    What is the keyword used in java to create an object?
    • A. 

      This

    • B. 

      New

    • C. 

      Sync

    • D. 

      New()


  • 75. 
    What is the correct syntax for java main method?
    • A. 

      Public void main(String[] args)

    • B. 

      Public static void main(string[] args)

    • C. 

      Public static void main()

    • D. 

      None of the above


  • 76. 
    A null reference may be used to access a static variable or method.
    • A. 

      True

    • B. 

      False


  • 77. 
    Native methods can be 'abstract'
    • A. 

      True

    • B. 

      False


  • 78. 
    Which of the following is not a Java keyword?
    • A. 

      Main

    • B. 

      Try

    • C. 

      Integer

    • D. 

      String


  • 79. 
    What is an Applet ?
    • A. 

      A Java program that does not run through a web browser

    • B. 

      A Java program that is run through a web browser

    • C. 

      An object-oriented programming language

    • D. 

      An interactive website


  • 80. 
    Java runs on _______.
    • A. 

      Windows

    • B. 

      Unix/Linux

    • C. 

      Mac

    • D. 

      All of the Above


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

      None of the above.

    • B. 

      Applets are run over the web.

    • C. 

      Applets can paint words, applications cannot.

    • D. 

      An application is only available on Windows


  • 82. 
    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

    • C. 

      To print words on the screen

    • D. 

      To write Java codes


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

      VariableName variableType;

    • B. 

      VariableName;

    • C. 

      VariableType;

    • D. 

      VariableType variableName;


  • 84. 
    What is an assignment statement ?
    • A. 

      Adding a number to an int

    • B. 

      Assigning a multiplication

    • C. 

      Assigning a name to a variable

    • D. 

      Assigning a value to a variable


  • 85. 
    What will be the value of “num” after the following statements? int num; num = (5+4); num = num / 9; num = 9;
    • A. 

      9

    • B. 

      1

    • C. 

      0

    • D. 

      Num


  • 86. 
    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. 

      &&

    • C. 

      |

    • D. 

      ||


  • 87. 
    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)

    • C. 

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

    • D. 

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


  • 88. 
    What is a loop ?
    • A. 

      A new type of Applet.

    • B. 

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

    • C. 

      A segment of code to be run infinite times

    • D. 

      A segment of code to be run once


  • 89. 
    What is essential in making sure that your loop is not infinite ?
    • A. 

      That your Boolean statement will at some point be false

    • B. 

      That there is a Boolean statement somewhere in your code

    • C. 

      That your Boolean statement will at some point be true

    • D. 

      All of the choices


  • 90. 
    Which is NOT a section of all types of loops ?
    • A. 

      Initialization

    • B. 

      Loop Body

    • C. 

      Test statement

    • D. 

      The word "while"


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

      Initialization

    • B. 

      Loop Body

    • C. 

      Test statement

    • D. 

      Update


  • 92. 
    What is the difference between private and public functions ?
    • A. 

      Public functions are free, you have to buy private ones

    • B. 

      Public functions are the only ones you can download

    • C. 

      Public functions can be used by anyone, private can only be used by other code in the class you are writing

    • D. 

      Public functions can’t be used


  • 93. 
    What does AWT stands for ?
    • A. 

      Advanced Window Toolkit

    • B. 

      Abstract window Toolkit

    • C. 

      Adjust Window Toolkit

    • D. 

      None of the choices


Back to top

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz
We have sent an email with your new password.