Shared Flashcard Set

Details

Java CS170 Chapter. 4
Quiz Questions
16
Computer Science
Undergraduate 1
10/13/2011

Additional Computer Science Flashcards

 


 

Cards

Term
What is the function of the dot operator?
Answer

a. It serves to separate the integer portion from the fractional portion of a floating point number
b. It allows one to access the data within an object when given a reference to the object
c. It allows one to invoke a method within an object when given a reference to the object
d. It is used to terminate commands (much as a period terminates a sentence in English)
e. Both (b) and (c) are correct
Definition
e. Both (b) and (c) are correct
Term
To create and initialize a TV variable named tv, you would write :
Answer

a. tv = new TV("Sony");

b. TV tv = "Sony";

c. TV tv = new TV("Sony");

d. TV tv = TV("Sony");

e. None of these are correct.
Definition
c. TV tv = new TV("Sony");
Term
The variable a has the value 4. After evaluating the expression : int x = a++; , x will have _____, and a will have _________.
Answer

a. 4, 4

b. 5, 5

c. 5, 4

d. 4, 5

e. None of these.
Definition
d. 4, 5
Term
The variable a has the value 5. What value will it contain after evaluating the expression : a += 4;
Answer

a. 4

b. 1

c. 8

d. None of these
Definition
d. None of these
Term
Assume that font is an initialized Font variable. Which of these lines contains a logical error?
Answer

1. String style = font.getStyle();

2. font.getFontName();

3. String name = getFontName();

4. int size = font.getSize();
Definition
2. font.getFontName();
Term
When drawing a rectangle, the fourth parameter is:
Answer

1. the vertical coordinate of the top of the rectangle

2. the width

3. the horizontal coordinate of the right edge of the rectangle

4. the height

5. the vertical coordinate of the bottom of the rectangle

6. the horizontal coordinate of the left edge of the rectangle
Definition
4. the height
Term
The parameters passed to the Graphics drawLine() method represent:
Answer

1. starting point, slope and distance

2. two end-points

3. starting point, angle and distance

4. one end-point only
Definition
2. two end-points
Term
You should normally call the setBackround() method from inside the _____________ method.
Answer

1. stop()

2. paint()

3. init()

4. run()
Definition
3. init()
Term
Consider the following statements.

int n = 157;
String y = String.format("%05d", n);

What is the value of y?
Answer

1. "157 "

2. " 157"

3. "157"

4. "00157"
Definition
4. "00157"
Term
Consider the following sequence of statements.

String str;
int num1, num2;
num1 = 13;
num2 = 24;
str = "The sum = " + num1 + num2;

What is the final value stored in str?
Answer

1. The sum = 13 + 24

2. The sum = 1324

3. The sum = 37

4. The sum = 13 24
Definition
2. The sum = 1324
Term
Assume that the following variables have been declared:
String str1 = "Q.E.D."; String str2 = "Arcturan Megadonkey"; String str3 = "Sirius Cybernetics Corporation";
Evaluate the following expression:
str3.charAt(9)
(Place only your answer in the text-box below. If the answer is a String, place it in double quotes; if the answer is an integer, type the number with no decimals; if the answer is a char value, place it in single quotes like 'c'.)
Definition
'b'

the answer is a char value
Term
Assume that the following variables have been declared:
String str1 = "Q.E.D."; String str2 = "Arcturan Megadonkey"; String str3 = "Sirius Cybernetics Corporation";
Evaluate the following expression:
str3.charAt(17)
(Place only your answer in the text-box below. If the answer is a String, place it in double quotes; if the answer is an integer, type the number with no decimals; if the answer is a char value, place it in single quotes like 'c'.)
Definition
's'

the answer is a char value
Term
Assume that the following variables have been declared:
String str1 = "Q.E.D."; String str2 = "Arcturan Megadonkey"; String str3 = "Sirius Cybernetics Corporation";
Evaluate the following expression:
str2.length()
(Place only your answer in the text-box below. If the answer is a String, place it in double quotes; if the answer is an integer, type the number with no decimals; if the answer is a char value, place it in single quotes like 'c'.)
Definition
19

the answer is an integer
Term
What is the result of evaluating the mixed-type expression shown here?
2.5 * 2 + 8 / 5.0 + 10 / 3
(Place only your answer in the text-box below. Remember to write real numbers like 2.0, and integers like 2. Put quotes around String results.).
Definition
9.6
Term
What is the result of evaluating the mixed-type expression shown here?
(5 * 7.0 / 2 - 2.5) / 5 * 2
(Place only your answer in the text-box below. Remember to write real numbers like 2.0, and integers like 2. Put quotes around String results.)
Definition
6.0
Term
What is the result of evaluating the mixed-type expression shown here?
10.0 / 2 / 4
(Place only your answer in the text-box below. Remember to write real numbers like 2.0, and integers like 2. Put quotes around String results.)
Definition
1.25
Supporting users have an ad free experience!