The Java Programming Test Quiz: Trivia!

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 Theolc
T
Theolc
Community Contributor
Quizzes Created: 1 | Total Attempts: 699
| Attempts: 699 | Questions: 35
Please wait...
Question 1 / 35
0 %
0/100
Score 0/100
1. Given the declaration int [ ] nums = {8, 12, 23, 4, 15}, what expression will display the first element in the array (ie the number 8)

Explanation

The correct answer is System.out.print("The number is : " + nums[0]);. This expression accesses the first element in the array by using the index 0. The expression "nums[0]" retrieves the value at the first index of the array, which is 8. The print statement then displays "The number is : 8" on the console.

Submit
Please wait...
About This Quiz
The Java Programming Test Quiz: Trivia! - Quiz

The Java Programming Test Quiz: Trivia! assesses knowledge in Java, focusing on object-oriented programming, class and object distinctions, and visibility of class members. This quiz is ideal for... see morelearners aiming to test their understanding of Java's core concepts. see less

2. What does GUI stand for?

Explanation

GUI stands for Graphical User Interface. This term refers to the visual elements and controls that allow users to interact with software or hardware devices. It provides a user-friendly way to navigate and operate a system, using icons, buttons, menus, and other graphical elements. GUIs have become the standard for most operating systems and applications, as they offer a more intuitive and visually appealing interface compared to text-based interfaces.

Submit
3. 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. However, private superclass members cannot be accessed directly by the subclass. Therefore, the correct answer is "public superclass member (and protected subclass members if it's in the same package)".

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

Explanation

The given code initializes an array called "nums" with the values {1, 2, 3, 4, 5, 6}. The statement "nums[1] + nums[3]" accesses the second element of the array (2) and the fourth element of the array (4), and adds them together. The sum of 2 and 4 is 6.

Submit
5. What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};

Explanation

The correct answer is `for (int i =0; i

Submit
6. How to define a JButton with the caption test?

Explanation

The correct way to define a JButton with the caption "test" is by using the syntax "JButton aButton=new JButton("test");". This line of code creates a new JButton object named "aButton" and assigns it the caption "test" using double quotes. The other options provided are incorrect syntax for creating a JButton with a caption.

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

Explanation

The correct package to use widgets such as JApplet, JFrame, JPanel, and JButton is javax.swing. This package contains the necessary classes and components for creating graphical user interfaces in Java. It provides a set of advanced GUI components and layout managers that can be used to create interactive and visually appealing applications.

Submit
8. An object could be ...

Explanation

The given correct answer suggests that an object could be anything. This implies that it can refer to any type of entity, regardless of its nature or purpose. It could be an algorithm, a data container, a program, or any other conceivable thing. This answer highlights the broad and inclusive nature of the term "object" and emphasizes its versatility and potential to encompass a wide range of possibilities.

Submit
9. If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:

Explanation

The size of the array "ar" is 6 because the given code initializes an array "ar" with 6 elements: 1, 2, 3, 4, 5, and 6. The size of an array refers to the number of elements it can hold, and in this case, the array "ar" can hold 6 elements.

Submit
10. Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[3]?

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. Therefore, the value of ar[3] is 4.

Submit
11. If none of the private/protected/public is specified for a member, that member 

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 and use the member, but classes outside of the package cannot access it.

Submit
12. Which one needs a web page to run?

Explanation

A Java Applet needs a web page to run because it is designed to be embedded within a web browser. It is a small application that is written in Java and can be executed within a web page using a Java-enabled web browser. The applet runs on the client-side and is downloaded from the web server along with the web page. It can interact with the web page's HTML content and can be used to add dynamic and interactive features to a website.

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

Explanation

Inheritance allows a derived subclass object to directly access any public superclass member. This means that the subclass can access any public methods or variables defined in the superclass. Additionally, if the subclass is in the same package as the superclass, it can also access protected subclass members. Private superclass members, however, cannot be accessed directly by the subclass.

Submit
14. Class B inherits from Class A, what cannot be said:

Explanation

not-available-via-ai

Submit
15. A UML association is ...

Explanation

A UML association is implemented as a Java attribute member because an association in UML represents a relationship between two or more classes. In Java, this relationship is typically implemented using instance variables or attributes in the classes involved in the association. These attributes store references to the associated objects, allowing them to interact with each other. Therefore, implementing a UML association as a Java attribute member is the most appropriate choice.

Submit
16. An array holds:

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 block of memory. This means that all the elements in an array have the same data type, such as integers, characters, or floats. By storing similar values of the same data type in an array, we can easily access and manipulate these values using indexing.

Submit
17. The range of indices for an array always start at:

Explanation

The range of indices for an array always starts at 0. In most programming languages, arrays are zero-indexed, meaning that the first element of the array is at index 0. This convention allows for simpler and more efficient memory management and indexing operations. Therefore, when accessing elements in an array, the programmer should start counting from 0.

Submit
18. If classes Student, Staff and Faculty extend class Person, which one makes sense:

Explanation

The correct answer is Person[] persons={new Faculty(), new Staff(), new Student()}. This makes sense because the class Person is the superclass of all the other classes (Student, Staff, and Faculty). Therefore, an array of type Person[] can hold objects of any of these classes, including Faculty, Staff, and Student. This allows for polymorphism, where objects of different classes can be treated as objects of their superclass.

Submit
19. Which is not a part of defining an object?

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, on the other hand, is usually used to provide additional information or details about the object, but it is not essential for defining the object itself.

Submit
20. What is a member of a class?

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. Attributes represent the data that an object can hold, while methods define the behavior or actions that the object can perform. Therefore, a member of a class can be either an attribute or a method.

Submit
21. A class is ...

Explanation

This answer is correct because a class is a blueprint or a template that defines the properties and behaviors of an object. It provides a structure and defines the characteristics and methods that an object of that class should have. It is an abstract definition because it does not represent a specific instance of an object, but rather a general concept or idea of what an object of that class should be.

Submit
22. The last value in an array called ar can be found at index:

Explanation

The last value in an array can be found at the index of ar.length - 1 because array indices start from 0. Therefore, the length of the array is always greater than the index of the last element by 1. So, to access the last element in the array, we need to subtract 1 from the length of the array.

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

Explanation

In a Java application, the main container that can be used is JFrame. JFrame is a class that provides a window with various functionalities such as title bar, minimize and maximize buttons, and close button. It acts as the main container for other components like buttons, panels, and applets. JApplet is used for creating applets, JPanel is used as a container for organizing components, and JButton is a component used for creating buttons within containers. Therefore, JFrame is the most suitable choice for serving as the main container in a Java application.

Submit
24. 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". Then, it enters a for loop where it initializes an integer variable "i" to 0 and continues looping as long as "i" is less than 4. In each iteration, it prints the character at the index "i" of the string "word". Since "i" increments by 2 in each iteration, it prints the characters at index 0 and index 2, which are "a" and "c" respectively. Therefore, the output of the code is "ac".

Submit
25. The size of a frame is set using ...

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. By calling this method, the programmer can dynamically set the size of the frame at runtime, based on their specific requirements.

Submit
26. The following prototype shows that a Cylinder subclass is derived from a superclass called Circle

Explanation

The correct answer is "class Cylinder extends Circle". This answer suggests that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit properties and behaviors from its superclass. In this case, the Cylinder subclass inherits the properties and behaviors of the Circle superclass, indicating that a Cylinder can be considered as a specialized type of Circle.

Submit
27. 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?

Explanation

The correct answer is "The relationship from ATM to ATM Display". In UML, an association represents a relationship between two classes. In this scenario, the ATM class has a relationship with the ATM Display class, indicating that the ATM class uses or interacts with the ATM Display class.

Submit
28. Which one adds the widget mainPanel to a frame in the constructor of the frame?

Explanation

The correct answer is "this.add(mainPanel)". This statement adds the widget "mainPanel" to the frame using the "add" method. The "this" keyword refers to the current instance of the class, which in this case is the frame. By calling the "add" method on the frame object and passing in "mainPanel" as an argument, the widget is added to the frame's content pane.

Submit
29. Which one is not correct?

Explanation

The given statement "Class and object are just different names for the same thing" is not correct. A class is a blueprint or template for creating objects, while an object is an instance of a class. In other words, a class defines the properties and behaviors that an object of that class will have. Objects are created from classes and can have different values for their properties. Therefore, a class and an object are not the same thing, but rather related concepts in object-oriented programming.

Submit
30. The most common use of an array is to:

Explanation

The correct answer is "perform the same operation on all elements in array". Arrays are used to store multiple values of the same type in a single variable. By using loops or other methods, we can easily iterate through each element of the array and perform the same operation on all of them. This allows for efficient and concise coding when dealing with repetitive tasks or calculations on a set of data.

Submit
31. How is the layout of widgets on a panel specified?

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, such as BorderLayout or GridLayout, that determines how the widgets will be arranged on the panel. By calling setLayout, the programmer can customize the layout to suit the needs of their application.

Submit
32. Object-Oriented Programming means ...

Explanation

Object-Oriented Programming means designing the application based on the objects discovered when analyzing the problem. It involves breaking down the problem into objects and designing the program based on these objects. Writing an algorithm before writing the program and having a test plan is not specific to Object-Oriented Programming and can be a part of any programming approach. Writing a program composed of Java classes is a specific implementation of Object-Oriented Programming, but it is not the definition of Object-Oriented Programming itself.

Submit
33. The size of an applet is set using ...

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 for the applet to be displayed on the webpage. The setSize() method is used to set the size of a component within the applet, not the applet itself. The width and height attributes of the class JApplet are not used to set the size of the applet.

Submit
34. A UML association from class A to class B means?

Explanation

An association in UML represents a relationship between two classes. In this case, the correct answer suggests that Class A has an attribute of type B, indicating that instances of Class A can have a reference to instances of Class B. This means that Class A can access the properties and behaviors of Class B through this association.

Submit
35. Which one adds the widget mainPanel to an applet in the init method of the applet?

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 widget mainPanel to the content pane.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 20, 2023 +

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

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 19, 2012
    Quiz Created by
    Theolc
Cancel
  • All
    All (35)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Given the declaration int [ ] nums = {8, 12, 23, 4, 15}, what...
What does GUI stand for?
With inheritance, a derived subclass object can directly access any
What would display from the following statements? int [ ] nums =...
What loop will display each of the numbers in this array on a separate...
How to define a JButton with the caption test?
Which package do you need to use widgets such as JApplet, JFrame,...
An object could be ...
If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of...
If none of the private/protected/public is specified for a member,...
Which one needs a web page to run?
With inheritance, a derived subclass object can directly access any
Class B inherits from Class A, what cannot be said:
A UML association is ...
An array holds:
The range of indices for an array always start at:
If classes Student, Staff and Faculty extend class Person, which...
Which is not a part of defining an object?
What is a member of a class?
A class is ...
The last value in an array called ar can be found at index:
Which one could be used as the main container in a Java application?
What displays from the following statements? String word =...
The size of a frame is set using ...
The following prototype shows that a Cylinder subclass is derived from...
We have three classes: ATM, ATM...
Which one adds the widget mainPanel to a frame in the...
Which one is not correct?
The most common use of an array is to:
How is the layout of widgets on a panel specified?
Object-Oriented Programming means ...
The size of an applet is set using ...
A UML association from class A to class B means?
Which one adds the widget mainPanel to an applet in the init...
Alert!

Advertisement