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;
Answer: d


2.

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

(a)  TRUE
(b)  FALSE
Answer:  b


3.

The extends keyword creates a new

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


4.

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

(a)  TRUE
(b)  FALSE
Answer:  b


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.
Answer:  b


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
Answer:  b


7.

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

    (a)  int i;
         i = 0;

         while ( i < 4 ) {
             readData();
         }

    (b)  int i;
         i = 0;

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

    (c)  double k;
         k = 0.0;

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

    (d)  int i;
         i = 0;

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

Answer:  b


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.
Answer:  b


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
Answer:  a


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
Answer:  c


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.
Answer:  d


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.
Answer:  d


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.
Answer:  b


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 '}'.
Answer:  a


15:

Both iteration and recursion can occur infinitely: An infinite loop occurs with iteration if the loop-continuation test never becomes false.   Infinite recursion occurs if the recursion step does not reduce the problem each time in a manner that converges on the base case.

(a)  TRUE
(b)  FALSE
Answer:  a