The Java Programming Test Quiz: Trivia!

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 Theolc
T
Theolc
Community Contributor
Quizzes Created: 1 | Total Attempts: 699
Questions: 35 | Attempts: 699

SettingsSettingsSettings
The Java Programming Test Quiz: Trivia! - 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. 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.

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

    Rate this question:

  • 3. 

    Which one is not correct?

    • A.

      An objects exists in memory in run time

    • B.

      A class needs to be instantiated as an object before being used

    • C.

      An object is a variable, where its type is the class used to declare the variable

    • D.

      Class and object are just different names for the same thing

    Correct Answer
    D. Class and object are just different names for the same thing
    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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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]);` because it initializes a variable `i` to 0, checks if `i` is less than 3, and increments `i` by 1 after each iteration. This loop will iterate over the array `nums` and print each element 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". 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".

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

    Rate this question:

  • 26. 

    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]);

    Correct Answer
    A. System.out.print("The number is : " + nums[0]);
    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.

    Rate this question:

  • 27. 

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

    Rate this question:

  • 28. 

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

    Rate this question:

  • 29. 

    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

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

    Rate this question:

  • 30. 

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

    • A.

      0

    • B.

      6

    • C.

      5

    • D.

      7

    Correct Answer
    B. 6
    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.

    Rate this question:

  • 31. 

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

    Rate this question:

  • 32. 

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

    Rate this question:

  • 33. 

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

    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 directly by the subclass. Therefore, the correct answer is "public superclass member (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.

      Student[] students={new Person(), new Staff(), new Faculty()};

    • D.

      Person[] persons={new Faculty(), new Staff(), new Student()};

    Correct Answer
    D. 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 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.

    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 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 19, 2012
    Quiz Created by
    Theolc
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.