PDA

View Full Version : Interfaces


courtrigrad
Dec13-04, 12:49 PM
Hello all

I know an interface is even more abstract then an abstract class. Let's say I want to make an interface called Furniture that implements two class called Chair and Table. What does this exactly mean? Can someone please clarify this? Thanks

public interface Furniture {

int quantity;
boolean table;



public class Chair implements Furniture {

public GetQuant()

Now what do i put in the two classes?

Thanks

Nylex
Dec13-04, 01:20 PM
I'm not too sure myself, cos it's been ages since I've done Java (!). You might like to read the section entitled "What is an interface?" (http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html) in the Java tutorial from Sun.

so-crates
Dec13-04, 01:51 PM
Interfaces can't have variables. An interface defines what function a class must implement if it declares itself to implement the interface. This allows you to declare an object that has the type interface, and then call the functions that the interface declared to several different classes of objects.

ramollari
Dec14-04, 01:46 AM
A crucial role of interfaces is to ensure loose coupling between classes. If a class shouldn't have knowledge of other classes, it can have a reference of the interface that those classes implement. For example if you write a GUI program MyProgram that handles events from a JButton, the JButton implementation doesn't need to have a reference to class MyProgram, but to interface ActionListener, which class MyProgram implements.
New syntax with interfaces includes kewords interface and implements.

The Idiot
Dec15-04, 11:28 AM
Interfaces, while they may not have "variables" may include static variables, though. For example, you could have CHAIR, TABLE, and ETC with values of 1, 2, and 3, and have a function definition "int getType();" which would return one of these numbers.

It was fun in my java class. I had some interfaces that I had to implement, and I even had a "class Name extends Name1 implements Name2". That was fun...