20130423-invent Java Quiz #

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 Rapidvalue
R
Rapidvalue
Community Contributor
Quizzes Created: 1 | Total Attempts: 87
Questions: 10 | Attempts: 87

SettingsSettingsSettings
20130423-invent Java Quiz # - Quiz


Questions and Answers
  • 1. 

     What is the difference between private and public functions ?

    • A.

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

    • B.

      Public functions are the only ones you can download

    • C.

      Public functions are free, you have to buy private ones

    • D.

      Public functions can’t be used

    Correct Answer
    A. Public functions can be used by anyone, private can only be used by other code in the class you are writin
    Explanation
    Public functions can be accessed and used by any code, whether it is within the same class or outside of it. On the other hand, private functions are only accessible and usable within the class they are defined in. They cannot be accessed or used by any other code outside of that class. Therefore, the main difference between public and private functions is their accessibility and usability by other code.

    Rate this question:

  • 2. 

    With inheritance, a derived subclass object can directly access any *

    • A.

      public superclass member (and protected subclass members if it's in the same package)

    • B.

      Protected, public or private superclass member

    • C.

      Public or private superclass member

    • D.

      Private superclass member

    Correct Answer
    A. 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. This means that the derived subclass object can access both public and protected superclass members, as long as it is in the same package as the subclass. However, it cannot access private superclass members directly.

    Rate this question:

  • 3. 

    What is a member of a class ?

    • A.

      a method a method

    • B.

      A sub-class

    • C.

      An attribute

    • D.

      Attribute or method

    Correct Answer
    D. Attribute or method
    Explanation
    A member of a class refers to any attribute or method that is associated with that class. It can be an attribute, which represents the data or state of an object, or it can be a method, which represents the behavior or actions that an object can perform. Therefore, a member of a class can be either an attribute or a method.

    Rate this question:

  • 4. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Protected methods in a class can be accessed by any subclass of that class. This means that subclasses inherit the protected methods from the parent class and can call them within their own code. This allows for code reuse and promotes the concept of encapsulation and inheritance in object-oriented programming. Therefore, the statement "Methods that are marked protected can be called in any subclass of that class" is true.

    Rate this question:

  • 5. 

    Choose the appropriate data type for this field: weightInKilos      

    • A.

      char

    • B.

      boolean

    • C.

      double

    • D.

      String

    Correct Answer
    C. double
    Explanation
    The appropriate data type for the field "weightInKilos" would be double because it suggests that the weight will be measured in decimal numbers, which can include fractions or decimals. The double data type allows for the storage of floating-point numbers with a larger range and higher precision compared to other data types like int or float.

    Rate this question:

  • 6. 

    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.

      Ace

    • C.

      Bd

    • D.

      Ac

    Correct Answer
    D. Ac
    Explanation
    The given code initializes a string variable "word" with the value "abcde". The for loop then iterates over the indices of the string from 0 to 4 with a step of 2. In each iteration, it prints the character at the current index.

    In the first iteration, i=0, so it prints the character at index 0 which is 'a'.
    In the second iteration, i=2, so it prints the character at index 2 which is 'c'.

    Therefore, the output is "ac".

    Rate this question:

  • 7. 

    Choose the best definition for a Class.      

    • A.

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

    • B.

      An action for a program

    • C.

      A group of students in a class

    • D.

      none of these

    Correct Answer
    A. An object definition, containing the data and function elements necessary to create an object
    Explanation
    A class is a blueprint or template for creating objects. It contains the data and function elements that define the properties and behaviors of the objects that will be created from it. This definition allows for the creation of multiple instances of objects with similar characteristics and functionality.

    Rate this question:

  • 8. 

    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.

      4

    • C.

      1+3

    • D.

      2+4

    Correct Answer
    A. 6
    Explanation
    The 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 second element (nums[1]) and the fourth element (nums[3]) of the array, which is 2 + 4 = 6.

    Rate this question:

  • 9. 

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

    • A.

      java.awt

    • B.

      Java.swing

    • C.

      Javax.gui

    • D.

      Javax.swing

    Correct Answer
    D. 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 in Java. It is an extension of the java.awt package and provides more advanced and customizable components for building GUI applications.

    Rate this question:

  • 10. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The methods wait(), notify(), and notifyAll() in the Object class need to be called from synchronized pieces of code because they are used for inter-thread communication and synchronization. When a thread calls the wait() method, it releases the lock on the object and waits until another thread calls the notify() or notifyAll() method to wake it up. This communication and synchronization between threads should be done within synchronized blocks or methods to ensure thread safety and prevent race conditions. Therefore, the statement is true.

    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
  • Nov 15, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 23, 2013
    Quiz Created by
    Rapidvalue
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.