Java Objective Test

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 Aniketve
A
Aniketve
Community Contributor
Quizzes Created: 2 | Total Attempts: 797
Questions: 93 | Attempts: 548

SettingsSettingsSettings
Java Objective Test - Quiz

.


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
    C. Writing an algorithm before writing your program and having a test plan
    Explanation
    Object-Oriented Programming means designing the application based on the objects discovered when analyzing the problem. This approach focuses on breaking down the problem into smaller, manageable objects and then designing the program around these objects. It also involves writing an algorithm before writing the program and having a test plan to ensure the program functions correctly. Writing a program composed of Java classes is a specific implementation of Object-Oriented Programming, but it does not encompass the entire concept.

    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 the member can be accessed by any class within the same package, but not by classes in other packages.

    Rate this question:

  • 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

    Correct Answer
    C. Class and object are just different names for the same thing
    Explanation
    The given answer is correct because it states that class and object are just different names for the same thing. However, this statement is not true. In object-oriented programming, a class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the properties and behaviors that an object of that class will have, but the class itself and the object are not the same thing.

    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
    A. Description
    Explanation
    The description is not a part of defining an object. When defining an object, we need to specify its name, methods, and associations with other objects. The description, although it may provide additional information about the object, is not essential for its definition.

    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 and public members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the class they are defined in and cannot be accessed by any derived class. Therefore, it cannot be said that B has access to private members of A.

    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 is associated with that class. It can be either an attribute, which represents the data or state of the class, or a method, which represents the behavior or actions that the class can perform. Therefore, a member of a class can be either an attribute or a method, making the answer "attribute or method" correct.

    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
    D. Class A has an attribute of type B
    Explanation
    A UML association from class A to class B means that class A has an attribute of type B. This means that instances of class A can have a reference to instances of class B as one of their attributes. It does not imply inheritance, that class B is defined within class A, or that class B has an attribute of type A.

    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 represents a relationship between two or more classes. In Java, this association is typically implemented as a Java attribute member, which means that a class will have a variable that represents the association with another class. This allows objects of one class to have a reference to objects of another class, enabling them to interact and collaborate. By implementing the association as a Java attribute member, the relationship between the classes can be easily established and accessed.

    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 answer "anything" is correct because the question states that an object could be anything. This means that it can be any physical or abstract entity, such as an algorithm, a data container, or a program. The word "anything" encompasses all possibilities and allows for a broad interpretation of what an object can be.

    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 varibale

    Correct Answer
    C. An abstract definition of an object
    Explanation
    A class is an abstract definition of an object because it serves as a blueprint or template for creating objects of that class. It defines the properties and behaviors that the objects of that class will have. The class itself is not an object, but rather a conceptual representation of the object. Objects are instances of a class, created based on the class definition, and they possess the characteristics and behaviors specified by the class.

    Rate this question:

  • 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

    Correct Answer
    A. The method setSize()
    Explanation
    The size of a frame is set using the method setSize(). This method allows the programmer to specify the width and height of the frame, ensuring that it is displayed at the desired size. By calling this method, the programmer can dynamically adjust the size of the frame during runtime, providing flexibility and customization options.

    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
    The correct answer is javax.swing. This package is needed to use widgets such as JApplet, JFrame, JPanel, and JButton. The javax.swing package provides a set of components and classes for creating graphical user interfaces (GUIs) in Java. It includes classes for creating and managing windows, buttons, panels, and other GUI elements. The java.awt package also provides GUI components, but javax.swing is generally preferred for its enhanced features and better performance. The javax.gui and java.swing options are incorrect as they do not exist in Java's standard library.

    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's Java Virtual Machine (JVM) and can interact with the web page's HTML content. Unlike a Java Application or Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure provided by a web page to be displayed and executed.

    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
    GUI stands for Graphical User Interface. It is a type of user interface that allows users to interact with electronic devices through graphical elements such as icons, buttons, and menus. This interface provides a visual representation of the system's functions and enables users to easily navigate and interact with the system without needing to use complex commands or programming languages.

    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 the specific layout manager they want to use for organizing the widgets on the panel. The layout manager determines the positioning and sizing of the widgets, providing a consistent and organized appearance to the user interface. By calling setLayout, the programmer can customize the layout to suit their needs and achieve the desired arrangement of widgets on the panel.

    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)" because it adds the widget mainPanel to the frame using the "add" method of the frame itself.

    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 because it is a top-level container that provides a window for the application. It allows the application to have a title bar, minimize and maximize buttons, and other features typically associated with a window. JApplet is used for creating applets, JPanel is used for organizing and grouping components, and JButton is a specific type of component used for creating buttons. Therefore, JFrame is the most suitable choice for the main container in a Java application.

    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 for creating a new JButton object is to use the "new" keyword followed by the class name, and then provide the desired caption 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 method getContentPane() returns the content pane of the applet, and the add() method is used to add the widget mainPanel to the content pane. Therefore, getContentPane().add(mainPanel) adds the widget mainPanel to an applet in the init method of the applet.

    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. These properties allow the developer to specify the width and height of the applet in pixels. This ensures that the applet is displayed in the desired size when it is embedded within a web page. The other options mentioned, such as using the method setSize() or the width and height attributes of the class JApplet, are not correct in this context.

    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 called ar can be found at index ar.length - 1 because the index of an array starts from 0. So, if the length of the array is n, the last element will be at index n - 1.

    Rate this question:

  • 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

    Correct Answer
    A. 6
    Explanation
    The given code initializes an array called "nums" with the values {1,2,3,4,5,6}. The statement "System.out.println((nums[1] + nums[3]));" prints the sum of the values 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 for (int i =0; i < 3; i++) System.out.println( nums[i]). This loop will iterate through the array "nums" using the variable "i" as the index. It will start at index 0 and continue until index 2 (since the condition is i < 3). Each iteration, it will print out the value at that index using the System.out.println() method. This loop will display each of the numbers in the 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 with the index 0 and increments by 2 in each iteration until the condition i < 4 is no longer true. In each iteration, it prints the character at the current index of "word".

    In the first iteration, it prints the character at index 0, which is "a".
    In the second iteration, it prints the character at index 2, which is "c".

    Therefore, the output of the code is "ac".

    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" is initialized with values {1,2,3,4,5}. The index of an array starts from 0, so ar[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 value of ar[4] is 5 because in the given declaration, the array "ar" is initialized with 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, which 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 expression "System.out.print("The number is : " + nums[0]);" will display the first element in the array (i.e., the number 8). This is because "nums[0]" accesses the element at index 0 in the array "nums", which is the first element. The expression concatenates the string "The number is : " with the value of "nums[0]" and prints it to the console.

    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
    A. Similar values of same data type
    Explanation
    An array holds similar values of the same data type because it is a data structure that allows us to store multiple elements of the same type in a contiguous memory location. This allows for efficient access and manipulation of the elements within the array. By storing similar values of the same data type, we can easily perform operations on the elements using array indexing and looping constructs.

    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, arrays are zero-based, meaning that the first element of the array is accessed using the index 0. This convention is widely followed in order to maintain consistency and simplicity in array operations. Therefore, when working with arrays, it is important to remember that the index of the first element is always 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 correct answer is "perform the same operation on all elements in array". Arrays are commonly used to store a collection of similar data types. By using loops or other methods, we can easily apply the same operation to each element in the array, such as performing calculations, updating values, or displaying information. This allows for efficient and organized processing of data in a uniform manner.

    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 because the array is initialized with 6 elements: 1, 2, 3, 4, 5, and 6. Therefore, the size of the array is equal to the number of elements it contains, which 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" because it indicates that the class "Cylinder" is a subclass that is derived from the superclass "Circle". This means that the "Cylinder" class inherits all the properties and methods of the "Circle" class, and can also have its own unique properties and methods.

    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
    The correct answer is "The relationship from ATM to ATM Display". In the given scenario, the ATM class has a relationship with the ATM Display class, which is represented as an association in UML. This association indicates that the ATM class interacts with the ATM Display class by calling its methods or accessing its attributes.

    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. Therefore, the correct answer is that a derived subclass object can directly access public superclass members 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 the classes Student, Staff, and Faculty are subclasses. Therefore, it is valid to create an array of type Person[] and assign objects of any of the subclasses to it.

    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 or template for creating objects. It defines the properties and behaviors that objects of that class will have. The data elements in a class are the variables or attributes that store information, while the function elements are the methods or functions that define the behavior of the objects.

    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. A class is a blueprint or template that defines the properties and behaviors of an object. When we create an object, we are creating a specific instance of that class, with its own unique set of values for the properties defined in the class. Therefore, an object can be seen as a concrete representation of a class, with its own state and behavior.

    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 suitable to be stored as a String data type.

    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 because the value "true" represents a boolean data type, which can only have two possible values: true or false.

    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 have any decimal places, so it can be represented using the integer data type. Integers are used to store whole numbers without any fractional part.

    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 with a fractional part, so it cannot be represented by an integer data type. The appropriate data type to store this value would be a double, which is a data type used to represent floating-point numbers with decimal places.

    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" would be char. Char data type is used to store a single character in Java. In this case, "A" is a single character and can be stored as a char data type.

    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 because it is most likely representing a whole number quantity of eggs. The double data type is used for decimal numbers, char is used for single characters, and boolean is used for true/false values.

    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 appropriate data type for the field "weightInKilos" would be double. This is because weight is typically measured using decimal numbers, and the double data type can store decimal values with a higher precision compared to float. Using char would not be appropriate as it can only store a single character. String would not be suitable as it is used to store textual data rather than numerical values. Boolean would not be appropriate either as it is used to represent true or false values.

    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
    Class names and Strings always need a capital letter because it is a common convention in programming languages to use capital letters to distinguish between different types of identifiers. Class names are typically written in CamelCase, where each word starts with a capital letter, while Strings are enclosed in quotation marks and can contain any combination of letters, numbers, and symbols. Using capital letters helps to improve code readability and maintain consistency in the naming conventions.

    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:

Quiz Review Timeline +

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 14, 2013
    Quiz Created by
    Aniketve
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.