Object Oriented Programming MCQs
Object Oriented Programming MCQs
Object Oriented Programming MCQs
(A) procedures.
(B) functions.
(C) methods.
(D) subroutines.
3. Which of the following Math class features do not use any parameters or
arguments?
(A) PI
(B) E
(C) final
(D) Both A and B
(A) 12
(B) 81
(C) 64
(D) 4
For questions 5-8 use the following Bank class information. It contains the
headings of the methods in the Bank class, along with a description.
public Bank()
// default constructor starts checking and savings account with zero
dollars.
Bank tom;
tom = new Bank();
Bank sue;
sue = new Bank();
tom.changeChecking(1000);
sue.changeChecking(1500);
System.out.println("sue: " + sue.getSavings());
System.out.println("tom: " + tom.getSavings());
9. Assume that rand is an object of the Random class. Which of the following
statements generates a random integer in the [400..1600] range?
(A) the type of parameter used with the construction of a new DecimalFormat
object.
(B) using the format method.
(C) using the output method.
(D) all of the above.
int n1 = 100;
int n2 = 200;
int n3 = n1 / n2;
if (n3 > 0)
{
n2 = n1;
n1 = n2;
}
else
{
n1 = n2;
n2 = n1;
}
System.out.println(n1 + " " + n2);
16. What is the value of num at the conclusion of the following program segment?
17. What is the value of num at the conclusion of the following program segment?
(A) 100
(B) 101
(C) 102
(D) Error message
int count = 1;
for (int k = 0; k < 100; k++)
count++;
System.out.println(count);
(A) 99
(B) 100
(C) 101
(D) 102
(A) 6 7
(B) 7 8
(C) 6 3
(D) 7 3
int sum = 0;
for (int k = 1; k < 9; k+=2)
sum += k;
System.out.println("sum: " + sum);
(A) sum: 8
(B) sum: 9
(C) sum: 16
(D) sum: 25
(A) 0
(B) 6
(C) 12
(D) 36
(A) requires that the class identifier precedes the method identifier.
(B) may be called with the method identifier only in certain circumstances.
(C) is only possible after a new object is constructed.
(D) uses the class identifier only for readability.
(C) method1
method2
method3
class Calc
{
public static void add(int p, int q)
{
int result = p + q;
System.out.println(p + " + " + q + " = " + result);
}
public static void sub(int p, int q)
{
int result = p - q;
System.out.println(p + " - " + q + " = " + result);
}
public static void mul(int p, int q)
{
int result = p * q;
System.out.println(p + " * " + q + " = " + result);
}
public static void div(int p, int q)
{
int result = p / q;
System.out.println(p + " / " + q + " = " + result);
}
}
29. Which of the following statements shows correct syntax to create an object of the
Piggy class?
30. An object is
39. A class, which can use all the features of an established class, is
40. An established class, whose members can all be used by a newly declared class, is
41. Which identifier shows up both in the superclass and the subclass?
43. How is information passed from the subclass constructor to the superclass
constructor?
45. Which of the following columns is the correct truth table for (A or B) and B ?
46. Which of the following columns is the correct truth table for (A or B) or A ?
int a, b;
a = some mystery int.
if (a > 100)
{
if (a < 50)
b = 1000;
else
b = 3000;
}
else
{
if (a > 150)
b = 2000;
else
b = 3000;
}
System.out.print(b);
(A) 1000
(B) 2000
(C) 3000
int x, y;
x = 1;
while (x < 3)
{
y = 1;
x++;
while (y < 3)
{
y++;
System.out.println(x + y);
}
}
(A) 4
(B) 5
(C) 6
(D) 7
55. How many ampersands (&) are displayed by the program segment below?
int n, p, q;
n = 5;
p = 1;
do
{
q = p;
while (q < n)
{
q += 2;
System.out.print("&");
}
p += 2;
}
while ( p < n);
(A) 1
(B) 2
(C) 3
(D) 5
56. Assume that you are writing a program, which will enter grades and average
them. You want this program to prevent the user from entering any grades that
are outside the range of [0..100]. Which of the following program segments will
only accept the desired input?
I. int grade
do
{
( prompt and get user input for grade )
}
while (grade < 0 || grade > 100);
(A) I only
(B) II only
(C) I & II only
(D) II and III only
(E) I and III only
57. Assume that you are executing a program segment, which repeats until user input
states to stop.
The user is prompted in some manner to enter 'Y', 'y', 'N' or 'n', where Y means
to repeat the
program segment and N means to stop execution. Which of the following
program segments will
only accept the desired input
I. char choice;
boolean ok;
do
{
( prompt user and get input for choice )
ok = (choice == 'Y' || choice == 'y' || choice == 'N' ||
choice == 'n');
}
while (!ok);
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II and III
59. An array is a
(A) data structure with one, or more, elements of the same type.
(B) data structure with LIFO access.
(C) data structure, which allows transfer between internal and external storage.
(D) data structure with one, or more, elements, called fields, of the same or
different data types.
int list[];
list = new int[100];
(A) 99
(B) 100
(C) 101
(D) 100 initial integers plus any additional integers required during program
execution
Segment1 Segment2
Which of the following is a true statement about the comparison of Segment1 and
Segment2?
(A) list[0] = 0
list[1] = 1
list[2] = 2
list[3] = 3
list[4] = 4
(B) list[0] = 1
list[1] = 2
list[2] = 3
list[3] = 4
list[4] = 5
(C) list[1] = 1
list[2] = 2
list[3] = 3
list[4] = 4
list[5] = 5
(D) list[1] = 2
list[2] = 3
list[3] = 4
list[4] = 5
66. A class
67. An object
(A) attributes.
(B) instance variables.
(C) fields.
(D) all of the above.
(A) encapsulation.
(B) inheritance.
(C) polymorphism.
(D) all of the above.
72. A constructor is
74. When simple data types are used for parameter passing,
(A) the actual current value of the simple data type's variable is copied.
(B) the initial value of the simple data type's variable is copied.
(C) the memory reference where the variable values are stored is copied.
(D) a new object of the data type is instantiated.
(A) the current values of the data attributes of the object are copied.
(B) the initial values of the object instantiation information are copied.
(C) the memory reference where the object information is stored is copied.
(D) a new object of the same class as the parameter object is instantiated.
I. String s1 = "Mambo";
(A) I only
(B) I and II only
(C) II and III only
(D) I, II and III
79. What information will be stored in string3 as a result of the statement below?
80. Assume that s1, s2 and s3 are String objects. Which statement(s) demonstrate(s)
string concatenation?
(A) s1 = s2.concat("Hello");
(B) s3 = s1 + s2;
(C) concat(s1,s2);
(D) Both A and B
Assume that intArray stores a random list of integers prior to calling whatSort.
How will the
Integers be arranged after a call to whatSort?
Assume that intArray stores a random list of integers prior to calling whatSort.
How will the
Integers be arranged after a call to whatSort?
(A) Data will be arranged in ascending order.
(B) Data will be arranged in descending order.
(C) The largest integer will be stored in last array element.
(D) The smallest integer will be stored in the first array element.
84. Assume that index represents the array location where a new array elements needs
to be deleted or an
existing array element needs to be deleted. Variable size represents the number of
elements
in intArray. Consider method whichOne below.
Method whichOne
85. Assume that index represents the array location where a new array elements needs
to be deleted or an
existing array element needs to be deleted. Variable size represents the number of
elements
in intArray. Consider method whichOne below.
Method whichOne
86. How does the Selection Sort compare to the Bubble Sort in execution efficiency?
(A) The Selection Sort is always faster than the Bubble Sort.
(B) The Bubble Sort is always faster than the Selection Sort.
(C) The Selection Sort is usually faster than the Bubble Sort with random
data.
(D) The Selection Sort is only faster than the Bubble Sort with sorted data.
87. Consider method selectionSort below. Assume that method swap exists, which
swaps the array
elements of intArray according to the provided index parameters.
88. Consider method selectionSort below. Assume that method swap exists, which
swaps the array
elements of intArray according to the provided index parameters.
89. How does the Selection Sort behave after all the data is sorted in an array?
(A) It stops making comparisons, just like the Smart Bubble Sort.
(B) The Regular Selection Sort continues sorting; the Smart Selection Sort
stops.
(C) The Selection Sort continues to make comparisons until every comparison
pass is finished.
(D) If the data is sorted already, the Selection Sort never starts, otherwise it
executes every loop.
90. Is the Binary Search always preferred over the Linear Search, and why?
(A) Yes, because the Binary Search is always faster than the Linear Search.
(B) Yes, because the Binary Search can search any type of data.
(C) No, because the Linear Search is faster than the Binary Search with sorted
data.
(D) No, because the Binary Search only works with sorted data, unlike the
Linear Search.
91. Assume that intArray contains the following set of sorted integers.
{100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200}
How many comparisons are made by a Binary Search method to find number
130?
(A) 2
(B) 3
(C) 4
(D) 5
92. Assume that intArray contains the following set of sorted integers.
{11,22,33,44,55,66,77,88,99}
How many comparisons are made by a Binary Search method to determine that
number 50
is not in the list?
(A) 2
(B) 3
(C) 4
(D) 5
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 11 12 13 14 15 16 17 18 19 20
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 11 12 13 14 15 16 17 18 19 20
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
(A) 1
(B) 5
(C) 25
(D) 125
(A) 5
(B) 39
(C) 125
(D) 195
(A) 1
(B) 10
(C) 50
(D) 75
(A) 5
(B) 20
(C) 24
(D) 120
(A) 1
(B) 11
(C) 30
(D) 120