1.
Object-Oriented Programming means
Correct Answer
C. Writing an algorithm before writing your program and having a test plan
Explanation
Object-Oriented Programming (OOP) refers to a programming paradigm that focuses on designing software based on objects. It involves analyzing the problem, identifying relevant objects, and designing the application accordingly. While writing a program composed of Java classes is a characteristic of OOP, it is not the definition of OOP itself. Writing an algorithm before writing the program and having a test plan are important steps in the development process, but they are not exclusive to OOP.
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 outside of the package.
3.
Which one is not correct?
Correct Answer
C. Class and object are just different names for the same thing
Explanation
The given statement that "Class and object are just different names for the same thing" is not correct. In object-oriented programming, a class is a blueprint or template for creating objects. A class defines the properties and behaviors that an object of that class will have. On the other hand, an object is an instance of a class. It is created using the class blueprint and represents a specific entity with its own set of properties and behaviors. 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
In object-oriented programming, defining an object involves specifying its methods, associations with other objects, and giving it a name. However, the description of an object is not a necessary part of its definition. While it can be helpful to provide a description for documentation or understanding purposes, 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
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 class they are defined in and cannot be accessed by any 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 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. These members define the characteristics and behaviors of the objects created from the class. Therefore, the correct answer is attribute or method, as both attributes and methods are considered members of a class.
7.
A UML association from class A to class B means
Correct Answer
D. Class A has an attribute of type B
Explanation
The correct answer is "Class A has an attribute of type B." This means that class A has a variable or attribute that is of type B, indicating a relationship between the two classes. This association does not imply inheritance, the class B being defined within class A, or class B having an attribute of type A.
8.
A UML association is ...
Correct Answer
A. Implemented as a Java attribute member
Explanation
In UML, an association represents a relationship between two or more classes. It is implemented as a Java attribute member, which means that it is represented as a variable or property within a class. This attribute member can hold a reference to an object of another class, establishing the association between them. By using this implementation, the classes can communicate and interact with each other through the association attribute, allowing them to access and manipulate the associated objects.
9.
An object could be ...
Correct Answer
A. Anything
Explanation
The given correct answer, "anything," suggests that an object could refer to any entity or thing. It could be an algorithm, a data container, a program, or any other entity. This answer implies that the term "object" is not limited to a specific category or definition, but rather encompasses a broad range of possibilities.
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 defines the properties and behaviors that an object of that class should have. It serves as a blueprint or template for creating objects with similar characteristics. A class does not represent a specific object itself, but rather describes the common attributes and methods that objects of that class should possess.
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 in pixels. By calling this method, the programmer can dynamically adjust the size of the frame during runtime to meet 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 answer is javax.swing. This package is needed to use widgets such as JApplet, JFrame, JPanel, and JButton. The javax.swing package provides classes and components for creating a graphical user interface (GUI) in Java. It includes various classes and methods that allow the creation and manipulation of GUI components, such as windows, buttons, panels, and applets.
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 program that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and is typically used to add interactive features to a website. Unlike a Java Application or a Java Stand-Alone Application, which can be run independently on a computer, a Java Applet requires the infrastructure of 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 icons and visual indicators. This interface uses images, buttons, menus, and other graphical elements to enable users to perform tasks easily and intuitively. GUIs are widely used in software applications, operating systems, and websites to enhance user experience and make it more user-friendly.
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 determines how the widgets will be arranged on the panel. Different layout managers have different rules for positioning and resizing the widgets, allowing for flexibility in the design of the user interface. By calling setLayout, the programmer can customize the layout to meet the specific requirements of the 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)" because it uses the "add" method to add the widget "mainPanel" to the frame.
17.
Which one could be used as the main container in a Java application?
Correct Answer
B. JFrame
Explanation
JFrame can be used as the main container in a Java application because it provides a window for the application and acts as a top-level container. It allows other components to be added to it and provides various methods and functionalities to handle user interactions and display content. JApplet, JPanel, and JButton are not suitable as main containers as they have specific purposes within a Java application, such as creating applets, organizing components, and creating buttons, respectively.
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 JButton class provides a constructor that takes a String parameter, which represents the text that will be displayed on the button. By using the "new" keyword, we create a new instance of the JButton class and assign it to the variable "aButton". The String "test" is passed as an argument to the constructor, setting the caption of the button to "test".
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 mainPanel widget to the content pane. This line of code adds the mainPanel widget to the applet's content pane in the init method.
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 of the applet within the HTML code. The setSize() method is used to set the size of components within the applet, not the overall size of 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 ar.length - 1 because arrays in most programming languages are zero-indexed, meaning the first element is at index 0. Therefore, the last element will be at the index equal to the length of the array minus one.
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 iterates over the array "nums" using the index variable "i" starting from 0 and going up to 2. It then prints each element of the array on a separate line using the System.out.println() method.
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 that starts with i=0 and increments i by 2 in each iteration until i
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.
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 arrays in most programming languages are zero-indexed, meaning that the first element is at index 0, the second element is at index 1, and so on. In this case, the fifth element of the array is at index 4, and it has a value of 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 the expression nums[0] accesses the first element in the array "nums" and concatenates it with the string "The number is : " to display the result.
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 means that all the elements in an array should have the same data type, such as integers, floats, characters, or strings. By storing similar values, we can easily access and manipulate the elements in the array using their indices.
29.
The range of indices for an array always start at:
Correct Answer
C. 0
Explanation
In programming, the range of indices for an array always starts at 0. This means that the first element in an array is accessed using the index 0, the second element with index 1, and so on. This convention is followed in many programming languages, including C, C++, Java, and Python. Starting the index at 0 allows for a more efficient and consistent way of referencing elements in an array.
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 us to store multiple values of the same data type in a single variable. By using a loop or iteration, we can easily access each element in the array and apply the same operation to all of them. This is particularly useful when we want to perform a repetitive task or calculation on a set of data.
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 given declaration "int [ ] ar = {1,2,3,4,5,6};" initializes an array with 6 elements. The numbers inside the curly braces represent the values of the elements in the array. Therefore, 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 in Java to indicate that a class is derived from another class. In this case, the subclass "Cylinder" 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 additional 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 relationship from ATM to ATM Display will be shown as an association in UML. This means that the ATM class is associated with the ATM Display class, indicating that the ATM uses the methods and properties of the ATM Display class.
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 public superclass members. This means that the derived subclass object can use any public member of its superclass without any restrictions. 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 object.
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 is because the class hierarchy suggests that Faculty, Staff, and Student are all types of Person. Therefore, an array of type Person can hold objects of any of these three classes. However, the other two options are not valid because they involve trying to assign objects of incompatible types to arrays.
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. It serves as a blueprint or template for creating objects of that class. The class defines the properties and behaviors that the objects of that class will have.
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 for creating objects. Objects have properties (attributes) and behaviors (methods) defined by the class. This definition accurately describes the concept of an object in the context of programming.
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 represented by the String data type. String data type is used to store text in programming languages.
39.
Choose the appropriate data type for this value: true
Correct Answer
D. Boolean
Explanation
The value "true" represents a boolean data type, which is used to store either true or false values. In this case, since the value is "true", the appropriate data type to store it would be boolean.
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 fractional or decimal part. Therefore, the appropriate data type for this value would be an integer (int). 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 with a fractional component, which cannot be represented accurately using an integer data type. Therefore, the appropriate data type for this value is double, which is used to store floating-point numbers with a higher precision than float data type.
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 because char is used to represent a single character in programming. In this case, "A" is a single character, so it 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 commonly used to represent whole numbers without any decimal places. Since the number of eggs is typically a whole number, using int would be the most suitable choice.
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 represented as a decimal number and the double data type can store decimal values with a higher precision compared to float. Using a double data type allows for more accurate and flexible calculations involving weight measurements.
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 standard convention in programming languages to use capital letters to differentiate between different types of identifiers. Class names represent the blueprint for creating objects, and by convention, they start with a capital letter to make them easily distinguishable from other identifiers. Similarly, Strings are a data type used to represent a sequence of characters, and by convention, they are also written with a capital letter to differentiate them from other variables or identifiers.
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.