| Thread Closed |
Interfaces |
Share Thread |
| Dec13-04, 12:49 PM | #1 |
|
|
Interfaces
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:
public interface Furniture {
int quantity;
boolean table;
Code:
public class Chair implements Furniture {
public GetQuant()
Thanks |
| Dec13-04, 01:20 PM | #2 |
|
|
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?" in the Java tutorial from Sun.
|
| Dec13-04, 01:51 PM | #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.
|
| Dec14-04, 01:46 AM | #4 |
|
|
Interfaces
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. |
| Dec15-04, 11:28 AM | #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... |
| Thread Closed |
Similar discussions for: Interfaces
|
||||
| Thread | Forum | Replies | ||
| Interfaces and waves | Engineering, Comp Sci, & Technology Homework | 0 | ||