Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Interface is even more abstract then an abstract class

  1. Dec 13, 2004 #1
    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

    Code (Text):
     public interface Furniture {

    int quantity;
    boolean table;

    Code (Text):
     public class Chair implements Furniture {

    public GetQuant()
    Now what do i put in the two classes?

  2. jcsd
  3. Dec 13, 2004 #2
    I'm not too sure myself, cos it's been ages since I've done Java (!). You might like to read the http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html [Broken] in the Java tutorial from Sun.
    Last edited by a moderator: May 1, 2017
  4. Dec 13, 2004 #3
    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.
  5. Dec 14, 2004 #4
    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.
  6. Dec 15, 2004 #5
    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...
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook