CC 013_Midterm Assignment2
CC 013_Midterm Assignment2
Midterm Assignment #2
1. Write the first line of a method named zool that takes three parameters: an int and
two Strings. (10 points)
2. Write a line of code that invokes zool, passing as arguments the value 11, the name of
your first pet, and the name of the street you grew up on. (10 points)
3. What is the output of the program. (10 points)
public static void zoop() {
baffle();
System.out.print("You wugga ");
baffle();
}
private double y;
public Sample() {
}
public Sample(int a, double b){
}
public void setSample(){
}
public void print(){
}
}
a. How many constructors does class Sample have?
b. Write the definition of the member setSample so that x is set to 10 and y is set
to 25.8.
c. Write the definition of the member print that prints the contents of x and y.
d. Write the definition of the default constructor of the class Sample so that the
instance variables are initialized to 0.
e. Write the definition of the constructor with parameters of the class Sample so
that the instance variable x is initialized to the value of a and the instance
variable y is initialized to the value of b.
f. Write a Java statement that creates the Sample object s and initializes the
instance variables of s to 20 and 35.0, respectively.
g. Write a Java statement that prints the values of the instance variables of s.