CSE110 – Chandler High School - Practice Classes & Objects
Last Name(print): ______First Name ______Date:
1. Given the implementation of the class NumberAdder, answer the following questions.
public class NumberAdder
{
/** Constructs a number adder with numbers given.
@param n1 the first number
@param the second number */
public NumberAdder(int n1, int n2)
{ num1 = n1;
num2 = n2;
}
public int getSum( )
{
return num1 + num2;
}
private int num1;
private int num2;
} // end class NumberAdder
a. List all instance variables in class NumberAdder: ______
b. How many constructors are in class NumberAdder: ______
Write the header for the constructor (s): ______
What is the return type of the constructor (s): ______
c. Add statements to the main ( ) method to create two objects of type NumberAdder (instantiate), named adder1 and adder2. Then add statements to instantiate adder1’s numbers to 10 and 15, and adder2’s numbers to 100 and 200. Then add statements to print their respective sums.
public class NumberAdderTest
{ public static void main (String args[ ] )
{
______
______
______
______
}
} // end class NumberAdderTest