Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
1.
|
Which of the following
are Java integer data types?
a. | byte, short, integer and
longInteger | c. | byteInt, shortInt, int and
longInt | b. | shortInt, int and longInt | d. | byte, short, int
and long |
|
|
2.
|
Which of the following
is not a common binary arithmetic operator for real numbers?
|
|
3.
|
The expression
++q will ____________ execute the same as the expression q++.
a. | always | c. | sometimes | b. | never | d. | always (provided that q is an int data
type) |
|
|
4.
|
What is the output of
the following program statement?
int q = 10; System.out.print(q +
" "); q += 20; System.out.println(q); q *= 5;
a. | 30 150 | c. | 10
30 | b. | 10 30 150 | d. | 1020 |
|
|
5.
|
What is the output of
the program segment below?
int age = 25; String firstName =
"John"; String lastName = "Doe"; System.out.println(firstName +
"\n" + lastName + "\n" + age);
a. | JohnDoe25 | c. | John Doe 25 | b. | John Doe 25 | d. | Error Message |
|
|
6.
|
Which of the following
programming features is/are part of Object Oriented Programming?
a. | Encapsulation | c. | Class
interaction | b. | Polymorphism | d. | All of the above |
|
|
7.
|
Object Oriented
Programming
a. | makes programs more reliable. | c. | uses a lot of intimidating vocabulary, which is not as bad as it
sounds. | b. | simulates real life. | d. | does all of the
above. |
|
|
8.
|
What is the value of
result in the following statement?
int result = Math.pow(-2,2);
a. | -4.0 | b. | -0.25 | c. | 0.25 | d. | 4.0 | e. | NaN |
|
|
9.
|
What is the value of
result in the following statement?
int result = Math.floor(9.999999);
a. | 10 | c. | 9 | b. | 9.999999 | d. | Error Message |
|
|
10.
|
Assume that a
and b are non-equal integers. What is the value of result in the following
statement?
int result = Math.sqrt(Math.min(a,b)-Math.max(b,a));
a. | -25.0 | b. | -5.0 | c. | 5.0 | d. | 25.0 | e. | NaN |
|
|
11.
|
Assume you have an 800 by 600 applet window and that
g is an object of the Graphics class. Which of the following commands will draw a
diagonal line from the top-left corner to the bottom-right corner?
a. | g.drawLine(0,0,799,599); | b. | g.drawLine(0,0,599,799); | c. | g.drawLine(0,799,0,599); | d. | g.drawLine(799,599,0,0); | e. | Both A and
D |
|
|
12.
|
Assume you have an 800
by 600 applet window and that g is an object of the Graphics class. Which of the
following program segments will make the entire applet window red?
a. | g.setColor(Color.red); g.drawRect(0,0,800,600); | b. | g.setColor(Color.red); g.drawRect(0,0,600,800); | c. | g.setColor(Color.red); g.fillRect(0,0,800,600); | d. | g.setColor(Color.red); g.fillRect(800,600,0,0); | e. | g.setColor(Color.red); g.fillRect(0,0,600,800); |
|
|
13.
|
The drawOval
method uses the exact same parameters as what 3 other method(s)?
a. | fillOval | c. | fillRect | b. | drawRect | d. | All of the above |
|
|
14.
|
Which of the following
sentences can be translated into a conditional statement?
a. | Tomorrow is the start of the second
semester. | c. | Your SAT score should be 1250. | b. | If you are a national merit finalist, you will receive a
scholarship. | d. | Go straight to jail; do not pass go; do not collect any
money. |
|
|
15.
|
What is the output of
the following program segment?
double bonus = 500.0; double sales
= 300000.0; if (sales >= 300000.0) bonus += 250.0;
System.out.println("Bonus: " + bonus); System.out.println("The End");
a. | Bonus: 50.0 The
End | c. | Bonus: 750.0 The
End | b. | Bonus: 500.0 The
End | d. | No output |
|
|
16.
|
What is the output of
the following program segment?
int k = 100; k /=3; if (k <
30) { k++; k = k % 5; }
else { k--; k = k % 5;
} System.out.println("k = "+k);
a. | k = 0 | b. | k = 1 | c. | k =
2 | d. | k = 30 | e. | k = 32 |
|
|
17.
|
What is the value of
num at the conclusion of the following program segment?
char
qwerty = 'B'; int num = 100; switch(qwerty) {
case 'A': num ++; break;
case 'B': num += 2;
case 'C': num += 3; break; case 'D': num += 4;
}
a. | 100 | b. | 102 | c. | 105 | d. | 109 | e. | Error
message |
|
|
18.
|
The do..while
loop structure uses what kind of Repetition?
a. | pre-condition | c. | fixed | b. | post-condition | d. | multi-condition |
|
|
19.
|
What is the output of
the following program segment?
for (int k = 0; k <= 10; k+=3)
System.out.println("What is OOP?");
a. | What is OOP? What is OOP? What is OOP? What
is OOP? What is OOP? What is OOP?
| b. | What is OOP? What is OOP? What is OOP? What
is OOP? What is OOP? | c. | What is OOP? What is OOP? What is OOP? What is
OOP? | d. | What is OOP? | e. | No Output |
|
|
20.
|
What is the output of
the following program segment?
int j; j = 25; while (j > 2)
{ j/=2; System.out.print(j
+ " "); }
a. | 25 12 6 3 | b. | 25 13 7 4 2 | c. | 25 12 6 3
1 | d. | 12 6 3 1 | e. | 12 6 3 |
|
|
21.
|
drawPolygon & fillPolygon are both methods of
the _______ class.
a. | Math | b. | Random | c. | DecimalFormat | d. | Polygon | e. | Graphics |
|
|
22.
|
nextInt
& nextDouble are both methods of which classes?
a. | Math and Random | d. | Polygon
and Graphics | b. | Random and
Scanner | e. | Graphics and Scanner | c. | DecimalFormat and
Color |
|
|
23.
|
What can you determine
from the source code of a program that displays random numbers if this line is near the top of
the file?
Random rand = new Random(12345);
a. | The output will be the same every time you execute the
program. | b. | The output will be different every time you execute the
program. | c. | You cannot determine anything without seeing the
program. |
|
|
24.
|
Look at this program
segment:
Random rand = new Random();
System.out.println(rand.nextInt(901)+100);
What is the range of numbers that
can be displayed by this program segment?
a. | 100..901 | c. | 100..1000 | b. | 100..999 | d. | 100..1001 |
|
|
25.
|
Which of the following
program segments generates a random integer in the range [1000 . . . 9999]
?
a. | int range = 9999 - 1000 + 1; int randInt = (int) Math.random() * range +
1000; | b. | int range = 9999 - 1000 + 1; int randInt = (int) (Math.random()) * range +
1000; | c. | int randInt = (int) (Math.random() * 9999) +
1000; | d. | int range = 9999 - 1000 + 1; int randInt = (int) (Math.random() * range) +
1000; |
|
|
26.
|
What is the output of the following program?
public class Q61
{ public
static void main(String args [ ])
{
method1();
method2();
method3();
}
public static void method1() {
System.out.println("Calling method 1"); }
public static void method2() {
System.out.println("Calling method 2"); }
public static void method3() {
System.out.println("Calling method 3"); }
}
a. | Calling method 1 Calling method
2 Calling method
3 | b. | Calling method 3 Calling method
2 Calling method
1 | c. | Calling method 1 Calling method
3 Calling method
2 | d. | Error message |
|
|
27.
|
Which of the following
method headings uses proper parameter declarations?
a. | public static void guess(double rate, double hours, int
deductions); | b. | public static void
guess(double rate, hours, int deductions); | c. | public static void
guess(rate, hours, deductions); | d. | public static void
guess(7.85, 42.5, 3); |
|
|
28.
|
The parameters in the
method call and the method heading must be the same
I.
quantity. II. sequence. III.
type.
a. | I only | b. | II only | c. | I & II
only | d. | II & III only | e. | I, II & III |
|
|
29.
|
In a java file which
class must be declared public?
a. | Every class that is contained in the
file. | c. | Only the class with the same name as the
file. | b. | Only the class or classes that must be accessed from
outside the file. | d. | Only the first class in the
file. |
|
|
30.
|
What is the output of the following program?
public class
Q69 {
public static void main(String args [
])
{
int x = 25;
int y =
10;
System.out.println(x + " + " + y + " = " +
Calc.add(x,y));
System.out.println(x + " - " + y + " = " +
Calc.sub(x,y));
System.out.println(x + " * " + y + " = " +
Calc.mul(x,y));
System.out.println(x +
" / " + y + " = " + Calc.div(x,y));
} }
class
Calc {
public static int add(int p, int q)
{
int result = p +
q;
return result;
}
public static int sub(int p, int q)
{
int result = p -
q;
return result;
}
public static int mul(int p, int q)
{
return p *
q;
}
public
static int div(int p, int q)
{
return p /
q;
} }
a. | 25 + 10 25 - 10 25 * 10 25 /
10 | b. | 25 + 10 = 35 25 - 10 = 15 25 *
10 = 250 25 / 10 = 2 | c. | 35 15
250 2 | d. | Error message |
|
|
31.
|
What is the essence of
encapsulation?
a. | Declare data attributes in a class as
private. | b. | Declare data attributes in a class as
public. | c. | Package the data and the methods that access that data
inside the same class. | d. | Package all the
data in one class and all the methods in another class. | e. | None of the above |
|
|
32.
|
What is the output of
the following program?
public class Q77 {
public static void main(String args [ ])
{
Q77.method(1);
Q77.method(3);
Q77.method(2); }
public static void method(int n)
{
System.out.println("Calling method " + n);
} }
a. | Calling method 1 Calling method 2 Calling method 3 | b. | Calling method 3
Calling method 2 Calling method
1 | c. | Calling method 1 Calling method 3 Calling method 2 | d. | Error
Message |
|
|
33.
|
Which of the following
method declarations can be a constructor?
I. public static Qwerty() {
start = 0; max = 1000; }
II. public Qwerty() { start = 0;
max = 1000; }
III. public
Qwerty(int s, int m) { start = s;
max = m; }
IV.
public void Qwerty() {
start = 0; max = 1000; }
V. public int Qwerty(int s, int m) { start = s;
max = m; }
a. | I only | b. | II only | c. | III only
| d. | II & III only | e. | IV and V only |
|
|
34.
|
A private
method
I. can only be accessed by methods of the same class.
II. is usually a helper method. III.
can never be a constructor.
a. | I only | b. | II only | c. | III
only | d. | I & II only | e. | I, II & III |
|
|
35.
|
Class interaction is
the process of
a. | using classes in the established standard Java Language
library. | c. | combining data and the methods, which process the data,
inside the same module. | b. | using features from
an existing class. | d. | dividing a program into multiple related files for each
class in the program. |
|
|
36.
|
Consider the following
class heading.
public class Person extends Student
What is not
true about the class interaction of that class heading?
a. | It indicates an "is-a" class interaction
between the two classes. | c. | It indicates that Person is the
superclass and Student is the subclass. | b. | It indicates an
inheritance relationship between Person and Student | d. | It indicates that
Student is the superclass and Person is the subclass. |
|
|
37.
|
Consider the following method, which is defined in
the Student class and the Person class. Assume that the Student class is a
subclass of the Person class.
public void showData() {
System.out.println(getData()); System.out.println( super.getData()); }
What is printed when method showData is called?
a. | Two identical values | c. | The value of the subclass getData followed by the value of the superclass
getData | b. | A compile error message | d. | The value of the
superclass getData followed by the value of the subclass
getData |
|
|
38.
|
What method/field
tells you how many elements are in a Java static array?
a. | The length method | c. | The
size method | b. | The length
field | d. | The size field |
|
|
39.
|
What is the output of
this program segment:
int list[] = new int[10];
for (int j = 0; j < 10; j++) System.out.print(
list[j] );
a. | 0 | b. | 0000000000 | c. | [0, 0, 0, 0,
0, 0, 0, 0, 0, 0] | d. | 10 unknown
numbers | e. | Error |
|
|
40.
|
What is the output of this program segment:
int list[] = new int[10]; for (int j = 0; j
< 10; j++) if (j == j)
list[j] = 7 else
list[j] = 0;
for
(int j = 0; j < 10; j++) System.out.print( list[j]
);
a. | 7000000000 | b. | 0700000000 | c. | 0000000070 | d. | 0000000007 | e. | 7777777777 |
|