A+ Computer Science Worksheet KEY
DIRECTIONS : Fill in the blank with the correct answer/output.
public class Folder
{
private int items;
private double value;
public Folder ( int it, double v ) {
items = it; value = v;
}
public void setItems(int it) { items = it; }
public void setValue(double v) { value = v; }
public int getItems() { return items; }
public double getValue() { return value; }
public String toString( ) { return "" + items + " " + value; }
}
1. How many constructor methods are there in Folder? _____1_________
2. How many instance variables are there in Folder? _____2_________
3. How many constant variables are there in Folder? _____0_________
4. How many accessor methods are there in Folder? _____3_________
5. How many modifier methods are there in Folder? _____2_________
6. Instance variables should always be defined with what access? ___private____
7. Constructor methods should always be defined with what access? __public____
8. Which of the following is a valid instantiation of Folder?
A. Folder a = new Folder;
B. Folder a = Folder();
C. Folder a = new Folder( 22, 11);
D. Folder a = new Folder( 3.2, 4.8);
9. Which of the following is a valid instantiation of Folder?
A. Folder a = new Folder;
B. Folder a = Folder(87);
C. Folder a = new Folder( 44 );
D. Folder a = new Folder( 34, 4.5);
10. What type of method is toString( ) ?
A. void B. return
C. new D. static
© A+ Computer Science – Worksheet – [Link]