20130423-invent Java Quiz #

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Rapidvalue
R
Rapidvalue
Community Contributor
Quizzes Created: 1 | Total Attempts: 87
| Attempts: 87 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1.  What is the difference between private and public functions ?

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.

Submit
Please wait...
About This Quiz
20130423-invent Java Quiz # - Quiz

The 20130423-Invent Java Quiz assesses understanding of Java programming concepts including access modifiers, inheritance, data types, and class members. It is designed to test key skills in writing and understanding Java code, making it relevant for learners aiming to improve their programming expertise.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2. The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.

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.

Submit
3. Choose the appropriate data type for this field: weightInKilos      

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.

Submit
4. Choose the best definition for a Class.      

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.

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

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.

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

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.

Submit
7. What is a member of a class ?

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.

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

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.

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

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

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Nov 15, 2023 +

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
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
 What is the difference between private and public functions ?
The methods wait(), notify() and notifyAll() in Object need to be...
Choose the appropriate data type for this field:...
Choose the best definition for a Class.     ...
What would display from the following statements?...
Methods that are marked protected can be called in any subclass of...
What is a member of a class ?
With inheritance, a derived subclass object can directly access...
What displays from the following statements?...
Which package do you need to use widgets such as JApplet, JFrame,...
Alert!

Advertisement