CONTENTS | PREV | NEXT Java Remote Method Invocation


2.4 Implementing a Remote Interface

The general rules for a class that implements a remote interface are as follows:

For example, the following code fragment defines the BankAcctImpl class, which implements the BankAccount remote interface and which extends the java.rmi.server.UnicastRemoteObject class:

package my_package;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class BankAccountImpl
	extends UnicastRemoteObject
	implements BankAccount
{
	public void deposit (float amount) throws RemoteException {
		...
	}
	public void withdraw (float amount) throws OverdrawnException,
		RemoteException {
		...
	}
	public float balance() throws RemoteException {
		...
	}
}


Note that if necessary, a class that implements a remote interface can extend some other class besides java.rmi.server.UnicastRemoteObject. However, the implementation class must then assume the responsibility for the correct remote semantics of the hashCode, equals, and toString methods inherited from the Object class.



CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.