1.
Object-Oriented Programming means ...
Correct Answer
B. Designing the application based on the objects discovered when analysing the problem
Explanation
Object-Oriented Programming (OOP) is an approach to software development that focuses on designing and organizing a program or system around objects, which are instances of classes representing real-world entities or concepts. In OOP, you analyze the problem domain and model it using objects, encapsulation, inheritance, and polymorphism to create a more organized and modular software structure. So, OOP involves designing the application based on the objects discovered during the problem analysis phase.
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 the member, but classes outside of the package cannot.
3.
Which of the following is not correct?
Correct Answer
C. Class and object are just different names for the same thing
Explanation
The explanation for the given correct answer is that class and object are not the same thing. A class is a blueprint or template for creating objects, while an object is an instance of a class that exists in memory at runtime. They have different roles and functionalities in object-oriented programming.
4.
Which is not a part of defining an object?
Correct Answer
C. Associations with other objects
Explanation
In the context of Java programming, defining associations with other objects is not typically considered a direct part of defining a single object. While objects can have relationships with other objects, the act of defining a single object usually focuses on its attributes (description), methods, and name. Associating with other objects is more about the relationships between different objects in a broader system.
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 members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the same class and cannot be accessed by its subclasses. Therefore, the statement "B has access to private members of A" cannot be said.
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 belongs to that class. It can be either an attribute, which represents the data associated with the class, or a method, which represents the behavior or actions that the class can perform. In object-oriented programming, classes are used to define objects, and attributes and methods are the building blocks that make up these objects. Therefore, a member of a class can be either an attribute or a method, or it can be both.
7.
A UML association from class A to class B means
Correct Answer
C. Class B has an attribute of type A
Explanation
This means that instances of Class B are associated with instances of Class A in a way that Class B contains an attribute whose type is Class A. It doesn't necessarily mean every instance of B has an A, but there is a relationship between the two classes.
For example, if you have a UML diagram with classes `Car` and `Engine`, an association from `Car` to `Engine` would imply that a `Car` has an attribute, say `carEngine,` whose type is `Engine.`
This is different from option D, which would imply that every instance of `Car` has an attribute of type `Engine,` which may not be the case in a general association. Associations express relationships, not direct containment or inheritance.
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 in UML, an association represents a relationship between two or more classes. In Java, this relationship is typically implemented by creating a member variable in one class that references an object of another class. This allows the two classes to interact and collaborate with each other. Therefore, implementing a UML association as a Java attribute member is the correct approach to represent the relationship between classes in the UML diagram.
9.
An object could be ...
Correct Answer
A. Anything
Explanation
The given correct answer for this question is "anything". This is because the question states that an object could be anything, including an algorithm, a data container, or a program. The term "anything" encompasses all possibilities and allows for flexibility in the definition of an object.
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 represents the blueprint or template for creating objects of that class. It defines the properties (attributes) and behaviors (methods) that the objects of that class will have. The class itself is not an object, but rather a description or definition of what an object of that class should be like. Objects are instances of classes, created based on the class definition, and they have their own unique state and behavior.
11.
The size of a frame is set using ...
Correct Answer
A. The method setSize()
Explanation
The correct answer is the method setSize(). The size of a frame is set using the method setSize() in Java. This method allows you to specify the width and height of the frame, and it can be called at runtime to dynamically change the size of the frame.
12.
Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?
Correct Answer
A. Javax.swing
Explanation
To use widgets such as JApplet, JFrame, JPanel, and JButton, you need to use the javax.swing package. This package provides classes and components for creating graphical user interfaces (GUIs) in Java. It includes a wide range of widgets and functionality for building interactive and visually appealing applications. The javax.gui, java.awt, and java.swing options are incorrect as they do not provide the necessary classes for creating these specific widgets.
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 using a Java Virtual Machine (JVM) plugin. The web page provides the necessary environment and resources for the applet to run, such as HTML, CSS, and JavaScript. Applets are commonly used for interactive web content, such as games or multimedia applications.
14.
What does GUI stand for?
Correct Answer
A. GrapHical User Interface
Explanation
The correct answer is "Graphical User Interface". GUI stands for Graphical User Interface, which refers to the visual elements (such as icons, buttons, and windows) that allow users to interact with a computer system. It provides a user-friendly way to navigate and operate software applications, making it easier for users to perform tasks and access information.
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 that will determine how the widgets are arranged on the panel. Different layout managers have different rules and algorithms for positioning and sizing the widgets, allowing for flexibility in the design of the user interface.
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 line of code adds the widget mainPanel to the frame using the "add" method. The "this" keyword refers to the current instance of the frame, and "mainPanel" is the widget that is being added.
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. It is a top-level container that provides a window for the application. It allows the addition of various components such as buttons, panels, and applets. It provides features like a title bar, minimize, maximize, and close buttons. The JFrame class also provides methods to handle events and perform actions. Therefore, it is commonly used as the main container for building graphical user interfaces in Java applications.
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 follows the format of creating a new JButton object and assigning it to the variable "aButton", while passing the string "test" as the caption parameter 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 correct answer is getContentPane().add(mainPanel) because the getContentPane() method returns the content pane of the applet, and the add() method is used to add the mainPanel widget to the content pane. This ensures that the mainPanel is added to the applet correctly.
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.
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 ar.length - 1 because array indices start at 0. So, if the length of the array is n, the indices will range from 0 to n-1. Therefore, the last value will be at the index ar.length - 1.
22.
What is displayed 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 code initializes an integer array named "nums" with the values {1, 2, 3, 4, 5, 6}. The statement "System.out.println((nums[1] + nums[3]));" prints the sum of the elements 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 the first option: for (int i =0; i < 3; i++) System.out.println( nums[i]). This loop uses a for loop with an integer variable i initialized to 0 and incremented by 1 each iteration. The loop condition is i < 3, so the loop will run three times. Inside the loop, the System.out.println statement is used to print each element of the nums 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 from 0 and increments by 2 until it reaches 4. Inside the loop, it prints the character at the index "i" of the string "word".
In the first iteration of the loop, when "i" is 0, it prints the character at index 0 which is 'a'. In the second iteration, when "i" is 2, it prints the character at index 2 which is 'c'. Since the loop condition is "
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 contains the elements {1,2,3,4,5}. The index 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 given declaration initializes an integer array "ar" with the 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. Therefore, the value of ar[4] 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 correct answer is System.out.print("The number is : " + nums[0]); because nums[0] accesses the first element in the array nums, which is 8.
28.
An array holds:
Correct Answer
B. Different values of same data type
Explanation
An array holds different values of the same data type. In programming, an array is a collection of elements of the same type. These elements can be of any type like integers, characters, floating point numbers, strings, etc. The elements in an array are stored in contiguous memory locations and can be accessed using indices. However, the values of these elements can be different. For example, an integer array can hold the numbers 1, 2, 3, etc., which are different values but all of the same type (integer).
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, including popular ones like C, C++, Java, and Python, arrays are zero-indexed. This means that the first element of an array is accessed using the index 0. Therefore, the correct answer is 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 most common use of an array is to perform the same operation on all elements in the array. Arrays allow for efficient storage and retrieval of multiple values of the same data type. By applying a single operation to each element in the array, tasks such as calculations, transformations, or comparisons can be easily performed on a large set of data. This allows for concise and efficient coding, as the same code can be applied to each element in the array without the need for repetitive code or manual iteration.
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. This is because the array has 6 elements inside the curly braces {1, 2, 3, 4, 5, 6}. Each element takes up one slot in the array, so the size of the array is equal to the number of elements it contains, which in this case 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". This is because the keyword "extends" is used to indicate that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit the properties and methods of its superclass, and by extending Circle, the Cylinder subclass can access and use the attributes and behaviors defined in the Circle class.
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
In the given scenario, the relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class has a reference to the ATM Display class, indicating that it uses or interacts with the ATM Display class in some way. The association represents a dependency between the two classes, where the ATM class relies on the ATM Display class for its functionality.
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 object. 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
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 both Staff and Faculty are subclasses of Person. Therefore, an array of type Person can hold objects of type Faculty, Staff, and Student, as they all inherit from Person.
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 for creating objects, defining their properties (data) and behaviors (functions). It encapsulates the attributes and methods that an object will possess, allowing multiple objects to be created from the same class with their own unique data values.
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, which is a blueprint or template for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class, and they can interact with other objects. This definition accurately captures the concept of an object in the context of programming and distinguishes it from the other options provided.
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 a textual data. Therefore, the appropriate data type to represent this value would be a String.
39.
Choose the appropriate data type for this value: true
Correct Answer
D. Boolean
Explanation
The correct answer is boolean. The value "true" is a boolean value, which represents a logical true or false. It is used to store and manipulate boolean data in programming. The int data type is used for storing whole numbers, double is used for storing floating-point numbers, and String is used for storing textual data. However, in this case, the value "true" is specifically a boolean value.
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 contain any decimal places. Therefore, the appropriate data type for this value would be "int" which stands for integer. Integers are used to represent whole numbers in programming languages.
41.
Choose the appropriate data type for this value: 5.5
Correct Answer
B. Double
Explanation
The value 5.5 is a decimal number, so the appropriate data type to represent it is double.
42.
Choose the appropriate data type for this value: A
Correct Answer
C. Char
Explanation
The appropriate data type for the value "A" is char. The value "A" represents a single character and can be stored in a char variable.
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. This is because the field is representing a count or quantity of eggs, which is typically a whole number and does not require decimal places. The int data type is used to store integer values, making it suitable for this scenario.
47.
Choose the appropriate data type for this field: weightInKilos
Correct Answer
C. Double
Explanation
The field "weightInKilos" suggests that it is meant to store a numerical value representing weight. The data type "double" is appropriate for this field because it allows for decimal values, which are commonly used to represent weight. The data types "char" and "boolean" are not suitable for storing numerical values, and the data type "String" is not ideal for numerical calculations or comparisons.
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
In programming, class names and Strings (textual data) always require a capital letter at the beginning. This convention helps differentiate them from other elements in the code and follows standard coding practices for readability and consistency.
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.