CIS 3115
Modern Programming Techniques
Exam #1 Sample Questions


  1. Given the following class:
    class Counter {
    	void up() {v++;}
    	void down() {v--;}
    	public String toString() {return v + "";}
    
    	private int v = 0;
    }
    		
    write an app class that illustrates the use of this class. At least two objects should be created and every method must be called at some point.

  2. Given the following class:
    class Name {
    	Name(String first, String last) {
    		this.first = first;
    		this.last = last;
    	}	
    
    	String getFirst() {return first;}
    	String getFirst() {return first;}
    	String getInitials() {return first.charAt(0) + "." + last.charAt(0) + ".";}
    
    	boolean equals(Name otherName) {return last.equals(otherName.last) && first.equals(otherName.first);}
    
    	public String toString() {return last + ", " + first;}
    
    	private String first, last;
    }
    		

  3. What is wrong with the following class?
    class C {
    	C(int v) {
    		this.v = v;
    	}
    
    	private int v = 0;
    }