1.
Object-Oriented Programming means ...
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.
2.
If none of the private/protected/public is specified for a member, that member
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.
3.
Which one is not correct?
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.
4.
Which is not a part of defining an object?
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.
5.
Class B inherits from Class A, what cannot be said:
Correct Answer
C. B has access to private members of A
6.
What is a member of a 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.
7.
A UML association from class A to class B means?
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.
8.
A UML association is ...
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.
9.
An object could be ...
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.
10.
A class is ...
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.
11.
The size of a frame is set using ...
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.
12.
Which package do you need to use widgets such as JApplet, JFrame, JPanel, and JButton?
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.
13.
Which one needs a web page to run?
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.
14.
What does GUI stand for?
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.
15.
How is the layout of widgets on a panel specified?
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.
16.
Which one adds the widget mainPanel to a frame in the constructor of the frame?
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.
17.
Which one could be used as the main container in a Java application?
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.
18.
How to define a JButton with the caption test?
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.
19.
Which one adds the widget mainPanel to an applet in the init method of the applet?
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.
20.
The size of an applet is set using ...
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.
21.
The last value in an array called ar can be found at index:
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.
22.
What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));
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.
23.
What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};
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.
24.
What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);
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".
25.
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[3]?
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.
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)
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.
27.
An array holds:
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.
28.
The range of indices for an array always start at:
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.
29.
The most common use of an array is to:
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.
30.
If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
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.
31.
The following prototype shows that a Cylinder subclass is derived from a superclass called Circle
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.
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?
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.
33.
With inheritance, a derived subclass object can directly access any
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.
34.
With inheritance, a derived subclass object can directly access any
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)".
35.
If classes Student, Staff and Faculty extend class Person, which one makes sense:
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.