INDA Fall 2000
Quiz #1

This quiz is open book, i.e., you may have ONE Java text book with you.  It does not have to be the Deitel and Deitel book if you have not been using that.  You may also have an X-English dictionary where X is a language of your choice.

The quiz is multiple choice.  At the top of a separate sheet of paper, please print clearly "INDA Quiz 1", your name and your personnummer.  Then, in a vertical column, write the numbers 1 through 15 and your answer choice for each question next to the corresponding number.

Each question will be worth 2 points.  I suggest you also mark your answer on the exam paper to take away with you.  The answers will be posted on the main page of the course web site shortly after the quiz and you will be able to see how you did right away.

Good luck!

1.

Which of the following statements does not alter a memory location?

(a) number = 12;
(b)  y = y + 2;
(c)  width = Integer.parseInt(input);
(d)  int a;

2.

Integer division results in rounding of any fractional part, so 5 / 3 yields 1.67 which rounds to 2.

(a)  TRUE
(b)  FALSE

3.

The extends keyword creates a new

(a)  instance
(b)  base class
(c)  super class
(d)  sub class

4.

The higher the screen resolution, the larger the applet appears on the screen.

(a)  TRUE
(b)  FALSE

5.

What is output by the following Java code segment?

int temp;
temp = 180;

if ( temp > 90 ) {
System.out.println( "This porridge is too hot." );
// cool down
temp = temp - ( temp > 150 ? 100 : 20 );
} else {
if ( temp < 70 ) {
System.out.println("This porridge is too cold.");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
}
}

if ( temp == 80 )
System.out.println( "This porridge is just right!" );

(a)  None of the above
(b)  This porridge is too hot.
This porridge is just right!
(c)  This porridge is just right!
(d)  This porridge is too hot.

6.

The value in parentheses after the type in a new operation specifies how many copies of the object are to be created.

(a)  TRUE
(b)  FALSE

7.

Which one of the following segments will call the method readData four times?

(a)  int i;
i = 0;

while ( i < 4 ) {
}

(b)  int i;
i = 0;

while ( i < 4 ) {
i = i + 1;
}

(c)  double k;
k = 0.0;

while ( k != 4 ) {
k = k + 1;
}

(d)  int i;
i = 0;

while ( i <= 4 ) {
i = i + 1;
}

8.

Java is considered a strongly typed language because:

(a)  Instance variables of the primitive data types are automatically assigned a default value.
(b)  Java requires all variables to have a type before they can be used in a program.
(c)  The primitive types in Java are portable across all computer platforms that support Java.
(d)  All of the above.

9.

Consider the following code segment:

switch( q ) {
case 1:
System.out.println( "apple" );
break;
case 2:
System.out.println( "orange" );
break;
case 3:
System.out.println( "banana" );
break;
case 4:
System.out.println( "pear" );
case 5:
System.out.println( "grapes" );
default:
System.out.println( "kiwi" );
}

Which of the following values for q will result in "kiwi" being output?

(a)  5 and anything greater than 5
(b)  2
(c)  1
(d)  3

10.

Which of the following statements about a do/while repetition structure is true?

(a)  The body of a do/while loop is executed only once.
(b)  The body of a do/while loop is executed only if the terminating condition is true.
(c)  The body of a do/while loop is always executed at least once.
(d)  None of the above

11.

Complete the following sentence:  Variables that are used inside a method should be declared as instance variables if

(a)  they are used only within the method.
(b)  they are arguments.
(c)  they are local variables.
(d)  their values must be saved between calls to the method.

12.

The purpose of (int) in the statement

rand = 1 + (int)(Math.random() * 6);
is:
(a)  to create an element of chance.
(b)  to be a scaling factor.
(c)  to shift the output value.
(d)  to truncate the floating point part of the product.

13.

A JButton can cause an event (i.e., a call to an event-handling method) if:

(a)  An event handler has been called.
(b)  The registered event handler implements the ActionListener interface.
(c)  The JButton has been added to JApplet.
(d)  The registered event handler extends the GUI.

14.

Which of the following statement describes block scope?

(a)  It begins at the identifier's declaration, and ends at the terminating right brace (}).
(b)  It is valid for one statement only.
(c)  It limits label scope to only the method in which it is defined.
(d)  It begins at the opening '{' of the class definition and terminates at the closing '}'.