Java Quiz: Toughest Questions! Trivia MCQ

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 Kdjaafar
K
Kdjaafar
Community Contributor
Quizzes Created: 2 | Total Attempts: 1,614
Questions: 93 | Attempts: 192

SettingsSettingsSettings
Java Quiz: Toughest Questions! Trivia MCQ - 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 (OOP) refers to a programming paradigm that focuses on designing software based on objects. It involves analyzing the problem, identifying relevant objects, and designing the application accordingly. While writing a program composed of Java classes is a characteristic of OOP, it is not the definition of OOP itself. Writing an algorithm before writing the program and having a test plan are important steps in the development process, but they are not exclusive to OOP.

    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 outside of the package.

    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 statement that "Class and object are just different names for the same thing" is not correct. In object-oriented programming, a class is a blueprint or template for creating objects. A class defines the properties and behaviors that an object of that class will have. On the other hand, an object is an instance of a class. It is created using the class blueprint and represents a specific entity with its own set of properties and behaviors. Therefore, a class and an object are not the same thing, but rather related concepts 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
    A. Description
    Explanation
    In object-oriented programming, defining an object involves specifying its methods, associations with other objects, and giving it a name. However, the description of an object is not a necessary part of its definition. While it can be helpful to provide a description for documentation or understanding purposes, it is not essential for defining the object itself.

    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 class they are defined in and cannot be accessed by any 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 either an attribute or a method. In object-oriented programming, a class is a blueprint for creating objects, and members are the variables (attributes) and functions (methods) associated with the class. These members define the characteristics and behaviors of the objects created from the class. Therefore, the correct answer is attribute or method, as both attributes and methods are considered members of a class.

    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
    The correct answer is "Class A has an attribute of type B." This means that class A has a variable or attribute that is of type B, indicating a relationship between the two classes. This association does not imply inheritance, the class B being defined within class A, or class B having 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
    In UML, an association represents a relationship between two or more classes. It is implemented as a Java attribute member, which means that it is represented as a variable or property within a class. This attribute member can hold a reference to an object of another class, establishing the association between them. By using this implementation, the classes can communicate and interact with each other through the association attribute, allowing them to access and manipulate the associated objects.

    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, "anything," suggests that an object could refer to any entity or thing. It could be an algorithm, a data container, a program, or any other entity. This answer implies that the term "object" is not limited to a specific category or definition, but rather encompasses a broad range of possibilities.

    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 defines the properties and behaviors that an object of that class should have. It serves as a blueprint or template for creating objects with similar characteristics. A class does not represent a specific object itself, but rather describes the common attributes and methods that objects of that class should possess.

    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 in pixels. By calling this method, the programmer can dynamically adjust the size of the frame during runtime to meet their specific requirements.

    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 classes and components for creating a graphical user interface (GUI) in Java. It includes various classes and methods that allow the creation and manipulation of GUI components, such as windows, buttons, panels, and applets.

    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 program that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and is typically used to add interactive features to a website. Unlike a Java Application or a Java Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure of 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 icons and visual indicators. This interface uses images, buttons, menus, and other graphical elements to enable users to perform tasks easily and intuitively. GUIs are widely used in software applications, operating systems, and websites to enhance user experience and make it more user-friendly.

    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 determines how the widgets will be arranged on the panel. Different layout managers have different rules for positioning and resizing the widgets, allowing for flexibility in the design of the user interface. By calling setLayout, the programmer can customize the layout to meet the specific requirements of the application.

    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 uses the "add" method to add the widget "mainPanel" to the frame.

    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
    JFrame can be used as the main container in a Java application because it provides a window for the application and acts as a top-level container. It allows other components to be added to it and provides various methods and functionalities to handle user interactions and display content. JApplet, JPanel, and JButton are not suitable as main containers as they have specific purposes within a Java application, such as creating applets, organizing components, and creating buttons, respectively.

    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 JButton class provides a constructor that takes a String parameter, which represents the text that will be displayed on the button. By using the "new" keyword, we create a new instance of the JButton class and assign it to the variable "aButton". The String "test" is passed as an argument to the constructor, setting the caption of the button to "test".

    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)". This is 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 line of code adds the mainPanel widget to the applet's content pane in the init method.

    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. This allows the developer to specify the desired width and height of the applet within the HTML code. The setSize() method is used to set the size of components within the applet, not the overall size of the applet itself. The width and height attributes of the class JApplet are not used to set the size of the applet.

    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 arrays in most programming languages are zero-indexed, meaning the first element is at index 0. Therefore, the last element will be at the index equal to the length of the array minus one.

    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 iterates over the array "nums" using the index variable "i" starting from 0 and going up to 2. It then prints each element of the array on a separate line using the System.out.println() method.

    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". Then, it enters a for loop that starts with i=0 and increments i by 2 in each iteration until i

    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 the values {1,2,3,4,5}. In an array, the index 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 arrays in most programming languages are zero-indexed, meaning that the first element is at index 0, the second element is at index 1, and so on. In this case, the fifth element of the array is at index 4, and it has a value of 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 the expression nums[0] accesses the first element in the array "nums" and concatenates it with the string "The number is : " to display the result.

    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 means that all the elements in an array should have the same data type, such as integers, floats, characters, or strings. By storing similar values, we can easily access and manipulate the elements in the array using their indices.

    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
    In programming, the range of indices for an array always starts at 0. This means that the first element in an array is accessed using the index 0, the second element with index 1, and so on. This convention is followed in many programming languages, including C, C++, Java, and Python. Starting the index at 0 allows for a more efficient and consistent way of referencing elements in an array.

    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 us to store multiple values of the same data type in a single variable. By using a loop or iteration, we can easily access each element in the array and apply the same operation to all of them. This is particularly useful when we want to perform a repetitive task or calculation on a set of data.

    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 given declaration "int [ ] ar = {1,2,3,4,5,6};" initializes an array with 6 elements. The numbers inside the curly braces represent the values of the elements in the array. Therefore, 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 in Java to indicate that a class is derived from another class. In this case, the subclass "Cylinder" 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 additional 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 relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class is associated with the ATM Display class, indicating that the ATM uses the methods and properties of the ATM Display class.

    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 public superclass members. This means that the derived subclass object can use any public member of its superclass without any restrictions. 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 directly by the subclass object.

    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 is because the class hierarchy suggests that Faculty, Staff, and Student are all types of Person. Therefore, an array of type Person can hold objects of any of these three classes. However, the other two options are not valid because they involve trying to assign objects of incompatible types to arrays.

    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. It serves as a blueprint or template for creating objects of that class. The class defines the properties and behaviors that the objects of that class will have.

    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 for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class. This definition accurately describes the concept of an object in the context of programming.

    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 represented by the String data type. String data type is used to store text in programming languages.

    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 value "true" represents a boolean data type, which is used to store either true or false values. In this case, since the value is "true", the appropriate data type to store it would be boolean.

    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 fractional or decimal part. Therefore, the appropriate data type for this value would be an integer (int). 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 with a fractional component, which cannot be represented accurately using an integer data type. Therefore, the appropriate data type for this value is double, which is used to store floating-point numbers with a higher precision than float data type.

    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 because char is used to represent a single character in programming. In this case, "A" is a single character, so it 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 commonly used to represent whole numbers without any decimal places. Since the number of eggs is typically a whole number, using int would be the most suitable choice.

    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 represented as a decimal number and the double data type can store decimal values with a higher precision compared to float. Using a double data type allows for more accurate and flexible calculations involving weight measurements.

    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 standard convention in programming languages to use capital letters to differentiate between different types of identifiers. Class names represent the blueprint for creating objects, and by convention, they start with a capital letter to make them easily distinguishable from other identifiers. Similarly, Strings are a data type used to represent a sequence of characters, and by convention, they are also written with a capital letter to differentiate them from other variables or identifiers.

    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 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 03, 2015
    Quiz Created by
    Kdjaafar
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.