Suppose i have a class that implements an interface, the interface is not implementing anything currently. This class and interface are bundled together in the same java program. So i have another program, and through a dependency i want to get that information from that class i spoke of in the first program. How would i set up my interfaces to do this? Currently i have that class just implementing both it's local interface, and my other one on the second program. Is this correct. so that i could have a class in the second program pull out that information? or am i miss/doing something wrong.

Thanks

Interfaces must contain methods which uses the classes object as a parameter. Look at ActionListener Interface, in this interface you will get actionPerformed method. This method uses ActionEvent object. All the backend work is done by ActionEvent object. You must implement your interface in a manner like this.

How are the interfaces related to the desire of the second class wanting to get something from the first class?

When a class implements an interface, it is required to define all the methods in the interface. An interface gives another datatype to the class that implements it. That is useful in java because of its strict typing requirements.

The class in the first program is getting data in and assigning it to some objects. I need that information in the other program. So in the first program the interface is set up correctly with all the methods in it, so i guess the part i'm not understanding is how to set up my second program to get that information via an interface. So the first program has this class with the data objects in it, and that class implements an interface with all the methods defined. So what must i do to get the other program to recieve those objects. I guess i'm failing to see how the wiring works.

set up my second program to get that information via an interface

The second class needs a reference to the first class that it can use to call its methods. If the reference is defined as an interface, then the second class can call any of that interface's methods.

You always need a reference to an object to call any of its methods, If the reference is defined as an interface you can only call the interface's methods. If the reference is defined as the class, then you can call any of the class's methods, including those defined in the interface.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.