The Ultimate Java Test For Beginners

Reviewed by Godwin Iheuwa
Godwin Iheuwa, MS (Computer Science) |
Database Administrator
Review Board Member
Godwin Iheuwa, a Database Administrator at MTN Nigeria, holds an MS in Computer Science, specializing in Agile Methodologies and Database Administration from the University of Bedfordshire and a Bachelor's in Computer Science from the University of Port Harcourt. His proficiency in SQL Server Integration Services (SSIS) and SQL Server Management Studio contributes to his expertise in database management.
, MS (Computer Science)
Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Xooxa
X
Xooxa
Community Contributor
Quizzes Created: 1 | Total Attempts: 32,000
Questions: 93 | Attempts: 32,007

SettingsSettingsSettings
The Ultimate Java Test For Beginners - Quiz

This is the ultimate Java test for all those Java developer-wannabes who have just began practicing the programming language. It consists of over 93 questions of basically Core Java. So, if you are one of them and want to have a solid practice session to strengthen your hold on the concepts and methods, take it right now.


Questions and Answers
  • 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

    Correct Answer
    B. Designing the application based on the objects discovered when analysing the problem
    Explanation
    Object-Oriented Programming (OOP) is an approach to software development that focuses on designing and organizing a program or system around objects, which are instances of classes representing real-world entities or concepts. In OOP, you analyze the problem domain and model it using objects, encapsulation, inheritance, and polymorphism to create a more organized and modular software structure. So, OOP involves designing the application based on the objects discovered during the problem analysis phase.

    Rate this question:

  • 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

    Correct Answer
    B. Is only accessible by other classes of the same package
    Explanation
    If none of the access modifiers (private, protected, public) is specified for a member, that member is only accessible by other classes of the same package. This means that any class within the same package can access the member, but classes outside of the package cannot.

    Rate this question:

  • 3. 

    Which of the following is not correct?

    • A.

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

    • B.

      An object 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

    Correct Answer
    C. Class and object are just different names for the same thing
    Explanation
    The explanation for the given correct answer is that class and object are not the same thing. A class is a blueprint or template for creating objects, while an object is an instance of a class that exists in memory at runtime. They have different roles and functionalities in object-oriented programming.

    Rate this question:

  • 4. 

    Which is not a part of defining an object?

    • A.

      Description

    • B.

      Methods

    • C.

      Associations with other objects

    • D.

      Name

    Correct Answer
    C. Associations with other objects
    Explanation
    In the context of Java programming, defining associations with other objects is not typically considered a direct part of defining a single object. While objects can have relationships with other objects, the act of defining a single object usually focuses on its attributes (description), methods, and name. Associating with other objects is more about the relationships between different objects in a broader system.

    Rate this question:

  • 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

    Correct Answer
    C. B has access to private members of A
    Explanation
    Since Class B inherits from Class A, it can access the protected members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the same class and cannot be accessed by its subclasses. Therefore, the statement "B has access to private members of A" cannot be said.

    Rate this question:

  • 6. 

    What is a member of a class

    • A.

      An attribute

    • B.

      A method

    • C.

      Attribute or method

    • D.

      A sub-class

    Correct Answer
    C. Attribute or method
    Explanation
    A member of a class refers to any attribute or method that belongs to that class. It can be either an attribute, which represents the data associated with the class, or a method, which represents the behavior or actions that the class can perform. In object-oriented programming, classes are used to define objects, and attributes and methods are the building blocks that make up these objects. Therefore, a member of a class can be either an attribute or a method, or it can be both.

    Rate this question:

  • 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

    Correct Answer
    C. Class B has an attribute of type A
    Explanation
     This means that instances of Class B are associated with instances of Class A in a way that Class B contains an attribute whose type is Class A. It doesn't necessarily mean every instance of B has an A, but there is a relationship between the two classes.
    For example, if you have a UML diagram with classes `Car` and `Engine`, an association from `Car` to `Engine` would imply that a `Car` has an attribute, say `carEngine,` whose type is `Engine.`
    This is different from option D, which would imply that every instance of `Car` has an attribute of type `Engine,` which may not be the case in a general association. Associations express relationships, not direct containment or inheritance.

    Rate this question:

  • 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

    Correct Answer
    A. Implemented as a Java attribute member
    Explanation
    A UML association is implemented as a Java attribute member because in UML, an association represents a relationship between two or more classes. In Java, this relationship is typically implemented by creating a member variable in one class that references an object of another class. This allows the two classes to interact and collaborate with each other. Therefore, implementing a UML association as a Java attribute member is the correct approach to represent the relationship between classes in the UML diagram.

    Rate this question:

  • 9. 

    An object could be ...

    • A.

      Anything

    • B.

      An algorithm

    • C.

      A data container

    • D.

      A program

    Correct Answer
    A. Anything
    Explanation
    The given correct answer for this question is "anything". This is because the question states that an object could be anything, including an algorithm, a data container, or a program. The term "anything" encompasses all possibilities and allows for flexibility in the definition of an object.

    Rate this question:

  • 10. 

    A class is...

    • A.

      An object

    • B.

      An executable piece of code

    • C.

      An abstract definition of an object

    • D.

      A variable

    Correct Answer
    C. An abstract definition of an object
    Explanation
    A class is an abstract definition of an object because it represents the blueprint or template for creating objects of that class. It defines the properties (attributes) and behaviors (methods) that the objects of that class will have. The class itself is not an object, but rather a description or definition of what an object of that class should be like. Objects are instances of classes, created based on the class definition, and they have their own unique state and behavior.

    Rate this question:

  • 11. 

    The size of a frame is set using ...

    • A.

      The method setSize()

    • B.

      Automatically in run-time

    • C.

      The width and height attributes of the class JFrame

    • D.

      WIDTH and HEIGHT properties of the window menu in Eclipse

    Correct Answer
    A. The method setSize()
    Explanation
    The correct answer is the method setSize(). The size of a frame is set using the method setSize() in Java. This method allows you to specify the width and height of the frame, and it can be called at runtime to dynamically change the size of the frame.

    Rate this question:

  • 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

    Correct Answer
    A. Javax.swing
    Explanation
    To use widgets such as JApplet, JFrame, JPanel, and JButton, you need to use the javax.swing package. This package provides classes and components for creating graphical user interfaces (GUIs) in Java. It includes a wide range of widgets and functionality for building interactive and visually appealing applications. The javax.gui, java.awt, and java.swing options are incorrect as they do not provide the necessary classes for creating these specific widgets.

    Rate this question:

  • 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

    Correct Answer
    C. A Java Applet
    Explanation
    A Java Applet needs a web page to run because it is a small application that is designed to be embedded within a web page. It is executed within a web browser using a Java Virtual Machine (JVM) plugin. The web page provides the necessary environment and resources for the applet to run, such as HTML, CSS, and JavaScript. Applets are commonly used for interactive web content, such as games or multimedia applications.

    Rate this question:

  • 14. 

    What does GUI stand for?

    • A.

      Graphical User Interface

    • B.

      Gimme Ur Internet

    • C.

      Grand User Interface

    • D.

      Graphical Useful Interface

    Correct Answer
    A. GrapHical User Interface
    Explanation
    The correct answer is "Graphical User Interface". GUI stands for Graphical User Interface, which refers to the visual elements (such as icons, buttons, and windows) that allow users to interact with a computer system. It provides a user-friendly way to navigate and operate software applications, making it easier for users to perform tasks and access information.

    Rate this question:

  • 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

    Correct Answer
    C. By calling the method setLayout
    Explanation
    The layout of widgets on a panel is specified by calling the method setLayout. This method allows the programmer to choose a specific layout manager that will determine how the widgets are arranged on the panel. Different layout managers have different rules and algorithms for positioning and sizing the widgets, allowing for flexibility in the design of the user interface.

    Rate this question:

  • 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);

    Correct Answer
    B. This.add(mainPanel);
    Explanation
    The correct answer is "this.add(mainPanel)". This line of code adds the widget mainPanel to the frame using the "add" method. The "this" keyword refers to the current instance of the frame, and "mainPanel" is the widget that is being added.

    Rate this question:

  • 17. 

    Which one could be used as the main container in a Java application?

    • A.

      JApplet

    • B.

      JFrame

    • C.

      JPanel

    • D.

      JButton

    Correct Answer
    B. JFrame
    Explanation
    A JFrame can be used as the main container in a Java application. It is a top-level container that provides a window for the application. It allows the addition of various components such as buttons, panels, and applets. It provides features like a title bar, minimize, maximize, and close buttons. The JFrame class also provides methods to handle events and perform actions. Therefore, it is commonly used as the main container for building graphical user interfaces in Java applications.

    Rate this question:

  • 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;

    Correct Answer
    B. JButton aButton=new JButton("test");
    Explanation
    The correct answer is JButton aButton=new JButton("test"). This is the correct way to define a JButton with the caption "test". The syntax follows the format of creating a new JButton object and assigning it to the variable "aButton", while passing the string "test" as the caption parameter in double quotes.

    Rate this question:

  • 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);

    Correct Answer
    D. GetContentPane().add(mainPanel);
    Explanation
    The correct answer is getContentPane().add(mainPanel) because the getContentPane() method returns the content pane of the applet, and the add() method is used to add the mainPanel widget to the content pane. This ensures that the mainPanel is added to the applet correctly.

    Rate this question:

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

    Correct Answer
    D. HTML properties WIDTH and HEIGHT of the APPLET tag.
    Explanation
    The size of an applet is set using the HTML properties WIDTH and HEIGHT of the APPLET tag.

    Rate this question:

  • 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

    Correct Answer
    D. Ar.length - 1
    Explanation
    The last value in an array can be found at the index ar.length - 1 because array indices start at 0. So, if the length of the array is n, the indices will range from 0 to n-1. Therefore, the last value will be at the index ar.length - 1.

    Rate this question:

  • 22. 

    What is displayed 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

    Correct Answer
    A. 6
    Explanation
    The code initializes an integer array named "nums" with the values {1, 2, 3, 4, 5, 6}. The statement "System.out.println((nums[1] + nums[3]));" prints the sum of the elements at index 1 and index 3 of the array, which are 2 and 4 respectively. Therefore, the output will be 6.

    Rate this question:

  • 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

    • C.

      For (i = 0; i

    • D.

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

    Correct Answer
    A. For (int i =0; i < 3; i++) System.out.println( nums[i]);
    Explanation
    The correct answer is the first option: for (int i =0; i < 3; i++) System.out.println( nums[i]). This loop uses a for loop with an integer variable i initialized to 0 and incremented by 1 each iteration. The loop condition is i < 3, so the loop will run three times. Inside the loop, the System.out.println statement is used to print each element of the nums array on a separate line.

    Rate this question:

  • 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

    Correct Answer
    B. Ac
    Explanation
    The given code initializes a string variable "word" with the value "abcde". It then enters a for loop that starts from 0 and increments by 2 until it reaches 4. Inside the loop, it prints the character at the index "i" of the string "word".

    In the first iteration of the loop, when "i" is 0, it prints the character at index 0 which is 'a'. In the second iteration, when "i" is 2, it prints the character at index 2 which is 'c'. Since the loop condition is "

    Rate this question:

  • 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

    Correct Answer
    C. 4
    Explanation
    The value of ar[3] is 4 because in the given declaration, the array ar contains the elements {1,2,3,4,5}. The index 3 refers to the fourth element in the array, which is 4.

    Rate this question:

  • 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

    Correct Answer
    D. 5
    Explanation
    The given declaration initializes an integer array "ar" with the values {1,2,3,4,5}. In an array, the index starts from 0, so ar[4] refers to the fifth element of the array. Therefore, the value of ar[4] is 5.

    Rate this question:

  • 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);

    Correct Answer
    A. System.out.print("The number is : " + nums[0]);
    Explanation
    The correct answer is System.out.print("The number is : " + nums[0]); because nums[0] accesses the first element in the array nums, which is 8.

    Rate this question:

  • 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

    Correct Answer
    B. Different values of same data type
    Explanation
    An array holds different values of the same data type. In programming, an array is a collection of elements of the same type. These elements can be of any type like integers, characters, floating point numbers, strings, etc. The elements in an array are stored in contiguous memory locations and can be accessed using indices. However, the values of these elements can be different. For example, an integer array can hold the numbers 1, 2, 3, etc., which are different values but all of the same type (integer).

    Rate this question:

  • 29. 

    The range of indices for an array always start at:

    • A.

      Whatever programmer specifies

    • B.

      1

    • C.

      0

    • D.

      Size of array

    Correct Answer
    C. 0
    Explanation
    The range of indices for an array always starts at 0. In most programming languages, including popular ones like C, C++, Java, and Python, arrays are zero-indexed. This means that the first element of an array is accessed using the index 0. Therefore, the correct answer is 0.

    Rate this question:

  • 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

    Correct Answer
    C. Perform the same operation on all elements in array
    Explanation
    The most common use of an array is to perform the same operation on all elements in the array. Arrays allow for efficient storage and retrieval of multiple values of the same data type. By applying a single operation to each element in the array, tasks such as calculations, transformations, or comparisons can be easily performed on a large set of data. This allows for concise and efficient coding, as the same code can be applied to each element in the array without the need for repetitive code or manual iteration.

    Rate this question:

  • 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

    Correct Answer
    C. 6
    Explanation
    The size of the array "ar" is 6. This is because the array has 6 elements inside the curly braces {1, 2, 3, 4, 5, 6}. Each element takes up one slot in the array, so the size of the array is equal to the number of elements it contains, which in this case is 6.

    Rate this question:

  • 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

    Correct Answer
    C. Class Cylinder extends Circle
    Explanation
    The correct answer is "class Cylinder extends Circle". This is because the keyword "extends" is used to indicate that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit the properties and methods of its superclass, and by extending Circle, the Cylinder subclass can access and use the attributes and behaviors defined in the Circle class.

    Rate this question:

  • 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

    Correct Answer
    B. The relationship from ATM to ATM Display
    Explanation
    In the given scenario, the relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class has a reference to the ATM Display class, indicating that it uses or interacts with the ATM Display class in some way. The association represents a dependency between the two classes, where the ATM class relies on the ATM Display class for its functionality.

    Rate this question:

  • 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 same package)

    • D.

      Protected, public or private superclass member

    Correct Answer
    C. Public superclass member (and protected subclass members if it's in the same package)
    Explanation
    Inheritance allows a derived subclass object to directly access any public superclass member. Additionally, if the subclass is in the same package as the superclass, it can also access protected subclass members. However, private superclass members cannot be accessed by the subclass object. Therefore, the correct answer is public superclass member (and protected subclass members if it's in the same package).

    Rate this question:

  • 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()};

    Correct Answer
    C. Person[] persons={new Faculty(), new Staff(), new Student()};
    Explanation
    The correct answer is "Person[] persons={new Faculty(), new Staff(), new Student()};". This makes sense because the class Person is the superclass, and both Staff and Faculty are subclasses of Person. Therefore, an array of type Person can hold objects of type Faculty, Staff, and Student, as they all inherit from Person.

    Rate this question:

  • 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

    Correct Answer
    B. An object definition, containing the data and function elements necessary to create an object
    Explanation
    A class is an object definition that contains the data and function elements necessary to create an object. In object-oriented programming, a class serves as a blueprint for creating objects, defining their properties (data) and behaviors (functions). It encapsulates the attributes and methods that an object will possess, allowing multiple objects to be created from the same class with their own unique data values.

    Rate this question:

  • 37. 

    Choose the best definition of an object

    • A.

      A thing

    • B.

      An instance of a class

    • C.

      Something you wear

    Correct Answer
    B. An instance of a class
    Explanation
    The correct answer is "an instance of a class." In object-oriented programming, an object is an instance of a class, which is a blueprint or template for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class, and they can interact with other objects. This definition accurately captures the concept of an object in the context of programming and distinguishes it from the other options provided.

    Rate this question:

  • 38. 

    Choose the appropriate data type for this value: "volatile"    

    • A.

      Int

    • B.

      String

    • C.

      Double

    • D.

      Boolean

    Correct Answer
    B. String
    Explanation
    The value "volatile" is a sequence of characters, which makes it a textual data. Therefore, the appropriate data type to represent this value would be a String.

    Rate this question:

  • 39. 

    Choose the appropriate data type for this value: true    

    • A.

      Int

    • B.

      Double

    • C.

      String

    • D.

      Boolean

    Correct Answer
    D. Boolean
    Explanation
    The correct answer is boolean. The value "true" is a boolean value, which represents a logical true or false. It is used to store and manipulate boolean data in programming. The int data type is used for storing whole numbers, double is used for storing floating-point numbers, and String is used for storing textual data. However, in this case, the value "true" is specifically a boolean value.

    Rate this question:

  • 40. 

    Choose the appropriate data type for this value: 1

    • A.

      Int

    • B.

      Double

    • C.

      String

    • D.

      Boolean

    Correct Answer
    A. Int
    Explanation
    The value "1" is a whole number and does not contain any decimal places. Therefore, the appropriate data type for this value would be "int" which stands for integer. Integers are used to represent whole numbers in programming languages.

    Rate this question:

  • 41. 

    Choose the appropriate data type for this value: 5.5    

    • A.

      Int

    • B.

      Double

    • C.

      Boolean

    • D.

      String

    Correct Answer
    B. Double
    Explanation
    The value 5.5 is a decimal number, so the appropriate data type to represent it is double.

    Rate this question:

  • 42. 

    Choose the appropriate data type for this value: A    

    • A.

      Int

    • B.

      Double

    • C.

      Char

    • D.

      String

    Correct Answer
    C. Char
    Explanation
    The appropriate data type for the value "A" is char. The value "A" represents a single character and can be stored in a char variable.

    Rate this question:

  • 43. 

    Choose the appropriate data type for this value: "1"    

    • A.

      String

    • B.

      Boolean

    • C.

      Int

    • D.

      Char

    Correct Answer
    A. String
    Explanation
    String's always have " " around them!

    Rate this question:

  • 44. 

    Choose the appropriate data type for this value: female    

    • A.

      Boolean

    • B.

      Int

    • C.

      Char

    • D.

      Double

    Correct Answer
    A. Boolean
    Explanation
    male / female = boolean (only two possible answers)

    Rate this question:

  • 45. 

    Choose the appropriate data type for this field: kindOfBird    

    • A.

      String

    • B.

      Int

    • C.

      Char

    • D.

      Double

    Correct Answer
    A. String
    Explanation
    example: kindOfBird = "Parrot"

    Rate this question:

  • 46. 

    Choose the appropriate data type for this field: numberOfEggs    

    • A.

      Double

    • B.

      Char

    • C.

      Boolean

    • D.

      Int

    Correct Answer
    D. Int
    Explanation
    The appropriate data type for the field "numberOfEggs" would be int. This is because the field is representing a count or quantity of eggs, which is typically a whole number and does not require decimal places. The int data type is used to store integer values, making it suitable for this scenario.

    Rate this question:

  • 47. 

    Choose the appropriate data type for this field: weightInKilos    

    • A.

      Char

    • B.

      String

    • C.

      Double

    • D.

      Boolean

    Correct Answer
    C. Double
    Explanation
    The field "weightInKilos" suggests that it is meant to store a numerical value representing weight. The data type "double" is appropriate for this field because it allows for decimal values, which are commonly used to represent weight. The data types "char" and "boolean" are not suitable for storing numerical values, and the data type "String" is not ideal for numerical calculations or comparisons.

    Rate this question:

  • 48. 

    Choose the appropriate data type for this field: isSwimmer    

    • A.

      Double

    • B.

      Boolean

    • C.

      String

    • D.

      Int

    Correct Answer
    B. Boolean
    Explanation
    isSwimmer - yes or no (only two possible answers = boolean)

    Rate this question:

  • 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

    Correct Answer
    A. Class names and Strings
    Explanation
    In programming, class names and Strings (textual data) always require a capital letter at the beginning. This convention helps differentiate them from other elements in the code and follows standard coding practices for readability and consistency.

    Rate this question:

  • 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

    Correct Answer
    A. Create an instance of a class (an object)
    Explanation
    Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.

    Rate this question:

Godwin Iheuwa |MS (Computer Science) |
Database Administrator
Godwin Iheuwa, a Database Administrator at MTN Nigeria, holds an MS in Computer Science, specializing in Agile Methodologies and Database Administration from the University of Bedfordshire and a Bachelor's in Computer Science from the University of Port Harcourt. His proficiency in SQL Server Integration Services (SSIS) and SQL Server Management Studio contributes to his expertise in database management.

Quiz Review Timeline +

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

  • Current Version
  • Apr 30, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Godwin Iheuwa
  • Apr 22, 2012
    Quiz Created by
    Xooxa
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.