Docsity

Java Quiz Solutions for CMSC 131, Spring 2009, Quizzes of Computer Science

Toggle sidebar
bg1
Name (printed):
Student ID #:
Section # (or TA’s:
name and time)
CMSC 131 Quiz Snow Spring 2009
1. (8 points) Give a brief definition for each of the following terms as used in Java. All you need to do
is to tell its purpose.
(a) stack
(b) heap
(c) parameter/argument
(d) class/object
2. Assume you are working with the following class. Assume there are no other instance variables or
methods.:
public class Dancer {
public int height;
public double weight;
public void spin(int count,String direction) {
...
}
}
(a) (2 points) Write a single statement that declares a Dancer variable and assigns to it a new
Dancer object.
(b) (3 points) For the Dancer object created in part a, write statements that will set the height to
64 and the weight to 110.
(c) (3 points) Write a statement that will cause this same Dancer object to spin to the ”right” a
total of 20 times by using the spin method.
More on back page...
pf2

Partial preview of the text

Download Java Quiz Solutions for CMSC 131, Spring 2009 and more Quizzes Computer Science in PDF only on Docsity!

Name (printed):

Student ID #:

Section # (or TA’s: name and time)

CMSC 131 Quiz Snow Spring 2009

  1. (8 points) Give a brief definition for each of the following terms as used in Java. All you need to do is to tell its purpose.

(a) stack

(b) heap

(c) parameter/argument

(d) class/object

  1. Assume you are working with the following class. Assume there are no other instance variables or methods.:

public class Dancer { public int height; public double weight;

public void spin(int count,String direction) { ... } }

(a) (2 points) Write a single statement that declares a Dancer variable and assigns to it a new Dancer object.

(b) (3 points) For the Dancer object created in part a, write statements that will set the height to 64 and the weight to 110.

(c) (3 points) Write a statement that will cause this same Dancer object to spin to the ”right” a total of 20 times by using the spin method.

More on back page...

  1. (4 points) What will be the output from the following code fragment?

String x = new String("dog"); String y = new String("dog"); String z = x;

if (x.equals(y)) { System.out.println("A"); } else { System.out.println("B"); } if (x == y) { System.out.println("C"); } else { System.out.println("D"); } if (z.equals(x)) { System.out.println("E"); } else { System.out.println("F"); } if (z == x) { System.out.println("G"); } else { System.out.println("H"); }