Interface is even more abstract then an abstract class

AI Thread Summary
An interface in Java, such as "Furniture," serves as a contract that defines methods a class must implement without containing variables. It allows for loose coupling between classes, enabling an object to reference the interface rather than specific classes. This means that classes like "Chair" and "Table" can implement the "Furniture" interface by defining the required methods. While interfaces cannot have instance variables, they can include static variables. For example, constants like CHAIR and TABLE can be defined with specific values, and methods like "int getType();" can be implemented to return these values. Understanding interfaces is crucial for designing flexible and maintainable code in Java.
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...
 
In my discussions elsewhere, I've noticed a lot of disagreement regarding AI. A question that comes up is, "Is AI hype?" Unfortunately, when this question is asked, the one asking, as far as I can tell, may mean one of three things which can lead to lots of confusion. I'll list them out now for clarity. 1. Can AI do everything a human can do and how close are we to that? 2. Are corporations and governments using the promise of AI to gain more power for themselves? 3. Are AI and transhumans...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Back
Top