Interface is even more abstract then an abstract class

Click For Summary

Discussion Overview

The discussion revolves around the concept of interfaces in Java, particularly in relation to abstract classes. Participants explore the definition and functionality of interfaces, their role in programming, and how they relate to class implementation.

Discussion Character

  • Conceptual clarification
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant asserts that an interface is more abstract than an abstract class and seeks clarification on implementing an interface called Furniture with classes Chair and Table.
  • Another participant suggests referring to the Java tutorial for additional information, indicating uncertainty about the topic.
  • It is claimed that interfaces cannot have variables, and they define functions that classes must implement if they declare themselves to implement the interface.
  • A participant discusses the importance of interfaces in ensuring loose coupling between classes, providing an example involving a GUI program and the ActionListener interface.
  • Another participant notes that while interfaces may not have variables, they can include static variables, providing an example of how to define types within an interface.

Areas of Agreement / Disagreement

Participants express differing views on the capabilities of interfaces, particularly regarding the presence of variables and static variables. There is no consensus on the specifics of interface implementation.

Contextual Notes

Some participants express uncertainty about Java syntax and the functionality of interfaces, indicating a potential gap in understanding or knowledge of current Java standards.

Who May Find This Useful

Individuals interested in Java programming, particularly those learning about object-oriented principles and interface implementation.

courtrigrad
Messages
1,236
Reaction score
2
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()

Now what do i put in the two classes?

Thanks
 
Computer science news on Phys.org
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 in the Java tutorial from Sun.
 
Last edited by a moderator:
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.
 
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.
 
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...
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
6
Views
1K
Replies
4
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K