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. This approach focuses on breaking down the problem into smaller, manageable objects and then designing the program around these objects. It also involves writing an algorithm before writing the program and having a test plan to ensure the program functions correctly. Writing a program composed of Java classes is a specific implementation of Object-Oriented Programming, but it does not encompass the entire concept.
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 the member can be accessed by any class within the same package, but not by classes in other packages.
3.
Which one is not correct?
Correct Answer
C. Class and object are just different names for the same thing
Explanation
The given answer is correct because it states that class and object are just different names for the same thing. However, this statement is not true. In object-oriented programming, a class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the properties and behaviors that an object of that class will have, but the class itself and the object are not the same thing.
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, although it may provide additional information about the object, is not essential for its definition.
5.
Class B inherits from Class A, what cannot be said:
Correct Answer
C. B has access to private members of A
Explanation
Since Class B inherits from Class A, it can access the protected and public members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the class they are defined in and cannot be accessed by any derived class. Therefore, it cannot be said that 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 any attribute or method that is associated with that class. It can be either an attribute, which represents the data or state of the class, or a method, which represents the behavior or actions that the class can perform. Therefore, a member of a class can be either an attribute or a method, making the answer "attribute or method" correct.
7.
A UML association from class A to class B means
Correct Answer
D. Class A has an attribute of type B
Explanation
A UML association from class A to class B means that class A has an attribute of type B. This means that instances of class A can have a reference to instances of class B as one of their attributes. It does not imply inheritance, that class B is defined within class A, or that class B has an attribute of type A.
8.
A UML association is ...
Correct Answer
A. Implemented as a Java attribute member
Explanation
A UML association represents a relationship between two or more classes. In Java, this association is typically implemented as a Java attribute member, which means that a class will have a variable that represents the association with another class. This allows objects of one class to have a reference to objects of another class, enabling them to interact and collaborate. By implementing the association as a Java attribute member, the relationship between the classes can be easily established and accessed.
9.
An object could be ...
Correct Answer
A. Anything
Explanation
The given answer "anything" is correct because the question states that an object could be anything. This means that it can be any physical or abstract entity, such as an algorithm, a data container, or a program. The word "anything" encompasses all possibilities and allows for a broad interpretation of what an object can be.
10.
A class is...
Correct Answer
C. An abstract definition of an object
Explanation
A class is an abstract definition of an object because it serves as a blueprint or template for creating objects of that class. It defines the properties and behaviors that the objects of that class will have. The class itself is not an object, but rather a conceptual representation of the object. Objects are instances of a class, created based on the class definition, and they possess the characteristics and behaviors specified by the class.
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, ensuring that it is displayed at the desired size. By calling this method, the programmer can dynamically adjust the size of the frame during runtime, providing flexibility and customization options.
12.
Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?
Correct Answer
A. 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 (GUIs) in Java. It includes classes for creating and managing windows, buttons, panels, and other GUI elements. The java.awt package also provides GUI components, but javax.swing is generally preferred for its enhanced features and better performance. The javax.gui and java.swing options are incorrect as they do not exist in Java's standard library.
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 a small application that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and can interact with the web page's HTML content. Unlike a Java Application or Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure provided by a web page to be displayed and executed.
14.
What does GUI stand for?
Correct Answer
A. GrapHical User Interface
Explanation
GUI stands for Graphical User Interface. It is a type of user interface that allows users to interact with electronic devices through graphical elements such as icons, buttons, and menus. This interface provides a visual representation of the system's functions and enables users to easily navigate and interact with the system without needing to use complex commands or programming languages.
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 the specific layout manager they want to use for organizing the widgets on the panel. The layout manager determines the positioning and sizing of the widgets, providing a consistent and organized appearance to the user interface. By calling setLayout, the programmer can customize the layout to suit their needs and achieve the desired arrangement of widgets on the panel.
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)" because it adds the widget mainPanel to the frame using the "add" method of the frame itself.
17.
Which one could be used as the main container in a Java application?
Correct Answer
B. JFrame
Explanation
A JFrame can be used as the main container in a Java application because it is a top-level container that provides a window for the application. It allows the application to have a title bar, minimize and maximize buttons, and other features typically associated with a window. JApplet is used for creating applets, JPanel is used for organizing and grouping components, and JButton is a specific type of component used for creating buttons. Therefore, JFrame is the most suitable choice for 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 answer is JButton aButton=new JButton("test"). This is the correct way to define a JButton with the caption "test". The syntax for creating a new JButton object is to use the "new" keyword followed by the class name, and then provide the desired caption in double quotes.
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 method getContentPane() returns the content pane of the applet, and the add() method is used to add the widget mainPanel to the content pane. Therefore, getContentPane().add(mainPanel) adds the widget mainPanel to an applet in the init method of the applet.
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. These properties allow the developer to specify the width and height of the applet in pixels. This ensures that the applet is displayed in the desired size when it is embedded within a web page. The other options mentioned, such as using the method setSize() or the width and height attributes of the class JApplet, are not correct in this context.
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 called ar can be found at index ar.length - 1 because the index of an array starts from 0. So, if the length of the array is n, the last element will be at index n - 1.
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 "System.out.println((nums[1] + nums[3]));" prints the sum of the values at index 1 and index 3 of the array, which are 2 and 4 respectively. Therefore, the output will be 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]). This loop will iterate through the array "nums" using the variable "i" as the index. It will start at index 0 and continue until index 2 (since the condition is i < 3). Each iteration, it will print out the value at that index using the System.out.println() method. This loop will display each of the numbers in the array 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". It then enters a for loop that starts with the index 0 and increments by 2 in each iteration until the condition i < 4 is no longer true. In each iteration, it prints the character at the current index of "word".
In the first iteration, it prints the character at index 0, which is "a".
In the second iteration, it prints the character at index 2, which is "c".
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 values {1,2,3,4,5}. The index of an array starts from 0, so ar[3] refers to the fourth element in the array, which is 4.
26.
Given the declaration : int [ ] ar = {1,2,3,4,5}; What is the value of ar[4]?
Correct Answer
D. 5
Explanation
The value of ar[4] is 5 because in the given declaration, the array "ar" is initialized with values {1,2,3,4,5}. In an array, the index starts from 0, so ar[4] refers to the fifth element of the array, which is 5.
27.
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 expression "System.out.print("The number is : " + nums[0]);" will display the first element in the array (i.e., the number 8). This is because "nums[0]" accesses the element at index 0 in the array "nums", which is the first element. The expression concatenates the string "The number is : " with the value of "nums[0]" and prints it to the console.
28.
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 memory location. This allows for efficient access and manipulation of the elements within the array. By storing similar values of the same data type, we can easily perform operations on the elements using array indexing and looping constructs.
29.
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-based, meaning that the first element of the array is accessed using the index 0. This convention is widely followed in order to maintain consistency and simplicity in array operations. Therefore, when working with arrays, it is important to remember that the index of the first element is always 0.
30.
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 commonly used to store a collection of similar data types. By using loops or other methods, we can easily apply the same operation to each element in the array, such as performing calculations, updating values, or displaying information. This allows for efficient and organized processing of data in a uniform manner.
31.
If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
Correct Answer
C. 6
Explanation
The size of the array "ar" is 6 because the array is initialized with 6 elements: 1, 2, 3, 4, 5, and 6. Therefore, the size of the array is equal to the number of elements it contains, which is 6.
32.
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" because it indicates that the class "Cylinder" is a subclass that is derived from the superclass "Circle". This means that the "Cylinder" class inherits all the properties and methods of the "Circle" class, and can also have its own unique properties and methods.
33.
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 the given scenario, the ATM class has a relationship with the ATM Display class, which is represented as an association in UML. This association indicates that the ATM class interacts with the ATM Display class by calling its methods or accessing its attributes.
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 by the subclass. Therefore, the correct answer is that a derived subclass object can directly access public superclass members 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
C. 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 and the classes Student, Staff, and Faculty are subclasses. Therefore, it is valid to create an array of type Person[] and assign objects of any of the subclasses to it.
36.
Choose the best definition for a Class.
Correct Answer
B. An object definition, containing the data and function elements necessary to create an object
Explanation
A class is an object definition that contains the data and function elements necessary to create an object. In object-oriented programming, a class serves as a blueprint or template for creating objects. It defines the properties and behaviors that objects of that class will have. The data elements in a class are the variables or attributes that store information, while the function elements are the methods or functions that define the behavior of the objects.
37.
Choose the best definition of an object
Correct Answer
B. An instance of a class
Explanation
The correct answer is "an instance of a class." In object-oriented programming, an object is an instance of a class. A class is a blueprint or template that defines the properties and behaviors of an object. When we create an object, we are creating a specific instance of that class, with its own unique set of values for the properties defined in the class. Therefore, an object can be seen as a concrete representation of a class, with its own state and behavior.
38.
Choose the appropriate data type for this value: "volatile"
Correct Answer
B. String
Explanation
The value "volatile" is a sequence of characters, which makes it suitable to be stored as a String data type.
39.
Choose the appropriate data type for this value: true
Correct Answer
D. Boolean
Explanation
The correct answer is boolean because the value "true" represents a boolean data type, which can only have two possible values: true or false.
40.
Choose the appropriate data type for this value: 1
Correct Answer
A. Int
Explanation
The value "1" is a whole number and does not have any decimal places, so it can be represented using the integer data type. Integers are used to store whole numbers without any fractional part.
41.
Choose the appropriate data type for this value: 5.5
Correct Answer
B. Double
Explanation
The value 5.5 is a decimal number with a fractional part, so it cannot be represented by an integer data type. The appropriate data type to store this value would be a double, which is a data type used to represent floating-point numbers with decimal places.
42.
Choose the appropriate data type for this value: A
Correct Answer
C. Char
Explanation
The appropriate data type for the value "A" would be char. Char data type is used to store a single character in Java. In this case, "A" is a single character and can be stored as a char data type.
43.
Choose the appropriate data type for this value: "1"
Correct Answer
A. String
Explanation
String's always have " " around them!
44.
Choose the appropriate data type for this value: female
Correct Answer
A. Boolean
Explanation
male / female = boolean (only two possible answers)
45.
Choose the appropriate data type for this field: kindOfBird
Correct Answer
A. String
Explanation
example: kindOfBird = "Parrot"
46.
Choose the appropriate data type for this field: numberOfEggs
Correct Answer
D. Int
Explanation
The appropriate data type for the field "numberOfEggs" would be int because it is most likely representing a whole number quantity of eggs. The double data type is used for decimal numbers, char is used for single characters, and boolean is used for true/false values.
47.
Choose the appropriate data type for this field: weightInKilos
Correct Answer
C. Double
Explanation
The appropriate data type for the field "weightInKilos" would be double. This is because weight is typically measured using decimal numbers, and the double data type can store decimal values with a higher precision compared to float. Using char would not be appropriate as it can only store a single character. String would not be suitable as it is used to store textual data rather than numerical values. Boolean would not be appropriate either as it is used to represent true or false values.
48.
Choose the appropriate data type for this field: isSwimmer
Correct Answer
B. Boolean
Explanation
isSwimmer - yes or no (only two possible answers = boolean)
49.
Which of the following always need a Capital letter ?
Correct Answer
A. Class names and Strings
Explanation
Class names and Strings always need a capital letter because it is a common convention in programming languages to use capital letters to distinguish between different types of identifiers. Class names are typically written in CamelCase, where each word starts with a capital letter, while Strings are enclosed in quotation marks and can contain any combination of letters, numbers, and symbols. Using capital letters helps to improve code readability and maintain consistency in the naming conventions.
50.
What is the role of the constructor?
Correct Answer
A. Create an instance of a class (an object)
Explanation
Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.