4 Declarations and Access Control

4.1

public class EditContext {

    private Object selected;

    public void setSelected(Object newSelected) {
        selected = newSelected;
    }

    public Object getSelected() {
        return selected;
    }
}

4.2

public interface Tool {
    public void setContext(EditContext newContext);
    public boolean isActive();
}

4.3

// Filename: Database.java

// Specify package
package com.megabankcorp.system;

// Allow usage of Account class simply by referring to the name Account.
import com.megabankcorp.records.Account;

// Class must be abstract since it has abstract methods.
public abstract class Database {
    // Abstract and available from anywhere.
    public abstract void deposit(Account acc, long amount);

    // Abstract and available from anywhere.
    public abstract void withdraw(Account acc, long amount);

    // Abstract and only available from package and subclasses.
    protected abstract long amount(Account acc);

    // Unmodifiable and only available from package.
    final void transfer(Account from, Account to, long amount) {
        withdraw(from, amount);
        deposit(to, amount);
    }
}



     
    ASPTreeView.com
     
    Evaluation has »ВСexpired.
    Info...