



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Intro/Computer Science: Java B; Subject: Computer Science & Engineering; University: University of California - San Diego; Term: Winter 2004;
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Page 2) Consider the following recursive function.
Which of the following is output as a result of the call Mystery( 1027 )? Circle the correct Letter. (5 pts)
Fill in the blanks. (24 pts โ 2 pts each)
Primitive data types can be directly inserted into ______________ while all other data structures require objects.
The keyword _________________ specifies that a variable is not modifiable after it is initialized.
In order to insert a primitive int value into an ArrayList, you must first wrap/box the int value into a(n) __________________ object. The ListIterator method used to check if there are any more elements in this iteration is ________________.
The _____________ operator dynamically allocates memory for an object of a specified type in the ________________ and returns a (what area of the Java Runtime Environment) ____________________ to that object. ____________________ variables are located in these objects.
_____________ is a hidden parameter passed to every _________________________ method and ___________________________.
Members of a class specified as _____________________ are accessible only to methods of the class.
Which method defined in class M2 below will be matched with the following method invocations? (12 pts โ 2 pts each) A) Method labeled with / 1 / B) Method labeled with / 2 / C) Both methods โ ambiguous D) Neither methods โ no match
public class M { / 1 / public int aMethod( float a, long b ) { /* method implementation here / } / 2 / public int aMethod( int a, double b ) { / method implementation here */ } }
Write the Letter (A-D) corresponding to the correct answer on the line in front of every method call.
Page 4) Indicate whether each of the following parts of a Java program is (A-H) and where in the Java Runtime Environment this lives (1-3) (1 pt each)
A) Class (static) variable 1) Method Area / Class Area B) Instance variable 2) Object in the Heap C) Local variable 3) Stack Frame in the Runtime Stack D) Parameter E) Constructor F) Static method G) Instance method H) Class definition Java program part Java Runtime area (Answer A-H in this column) (Answer 1-3 in this column)
public class M4 { ________ M public char actor; ________ actor ________ private static int ellected; ________ ellected ________ public static int getEllected() { return ellected; } ________ getEllected ________ } public class SomeOtherClass { ________ SomeOtherClass private double digit; ________ digit ________ public static void main( String[] args ) { ________ main ________ ________ args ________ M4 ref; ________ ref ________ ref = new M4(); (where ref is pointing) ________ ... // *** HERE *** } public int foo( boolean test ) { ... } ________ foo ________ ________ test ________ }
Write a statement that could appear in the code above at the line marked //*** HERE *** that
a) assigns the return value of calling foo() passing the expression "5 less than or equal to 9" to actor in the object referenced by ref. Hint: Be aware of the types. (6 pts)
b) assigns the value in the private variable ellected in class M4 to digit. (6 pts)