CS 10: Introduction to Computer Programming

Final Examination

Closed-Book, 3 hours, Fall 1997

General Instructions



1. Describe the difference between public, private, and protected. Ignore differences having to do with packages.

2.  What is the meaning of the keyword this?  Illustrate the meaning with a class definition that uses it.

3. Describe what it means when a data member is declared static.   Illustrate the meaning with a class definition that uses it.

4. Give an example of an overloaded constructor (of your own design or from Java's class libraries).

5.  Give a method that takes a 2-dimensional array of double as an argument, and puts a random number in [0, 1) in each element.

6.  Give a method that takes a 3-dimensional array of int as an argument, and returns the sum of the elements whose indices have a sum that is evenly divisible by 3.  For example, if the array has element [1][1][1], then that element's value is part of the sum, because 1 + 1 + 1 is evenly divisible by 3.  On the other hand,  if the array has element [1][1][2], then that element's value is not part of the sum, because 1 + 1 + 2 is not evenly divisible by 3. 

7. Give a method that has 2 int array arguments.  Assume that they each have at least 2 elements.  The method puts the largest element in the first array into the first element of the second array, and the second-largest element in the first array into the second element of the second array.

8.  Give a Java applet that draws a 8 X 8 checker board (of black and red squares), where each square on the board has an edge length of 10 pixels.  The upper left corner of the board has pixel coordinates (0, 0).

9.  As applied to methods, what is the meaning of the keyword super?   Illustrate the meaning with some class definitions. (Hint: at least 2 class definitions are needed).

10. Give an example in Java of call-by-value and call-by-reference.  Describe the difference.