Exam 1 Practice Questions


  1. Explain the main parts of a method header.
  2. Write a method that takes as input an array of integers and returns the sum of all elements in the array.
  3. True or False: it is possible for a class to implement multiple interfaces.
  4. True or False: it is possible for a class to extend multiple other classes.
  5. True or False: a class that implements the Comparable interface must implement the .equals method.
  6. Can a class extend an abstract class and NOT implement all of the abstract methods of the superclass? If so, explain how. If not, explain why not.
  7. Which of the following designs of a Chicken class would be most appropriate? For full credit, explain your selection:
  8. Do you think that checked exceptions are good or bad? Why?
  9. Consider the classes defined below. What would be the output of the following code fragment? If a statement will cause an error, indicate that as well.
Account a1 = new Account("Bob Smith");
a1.printInfo();
a1.increaseSpace(256);

EmailAccount ea1 = new EmailAccount("Jane Forester", "jane@abc.com", 32);
ea1.printInfo();
ea1.increaseSpace(256);

Account a2 = ea1;
a2.printInfo();
a2.increaseSpace(256);

EmailAccount ea2 = (EmailAccount)a2;
ea2.printInfo();
ea2.increaseSpace(256); 

public abstract class Account {    
	protected String holder;    
	public Account(String holder) {
		this.holder = holder;    
	}    
	public void printInfo() {
		System.out.println("Account Holder: " + holder);    
	}
}

public class EmailAccount extends Account {    
	private String address;    
	private int storagespace;    
	public EmailAccount(String holder, String address, int storagespace) {
		super(holder);
		this.address = address;
		this.storagespace = storagespace;    
	}    
	public void printInfo() {
		super.printInfo();
		System.out.println("Address: " + address);    
	}    
	public void increaseSpace(int amount) {
		storagespace += amount;    
	}
}

Sami Rollins

Date: 2007-09-26