0

Hi i am new to Java and i hav a program to do where i am given an interface with all its methods in it then i am given a class that implements the interface but also has some of its own methods. But a method in the interface is given as a method in class, (they have the same name and parameters). Do you have separate code for each method?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ezzaral
0

Interfaces do not have any code themselves. They are a set of method declarations that are required by a class that implements that interface. The interface is a guarantee that those methods are available on any class that implements it. The code for those methods goes in the class that is implementing it.

0

But the class methods are given separately and it has a method with the same name as one given in the interface!

0

Yes, that is the point. The interface is just a list of methods. They have no code in them. The class that implements that interface supplies the code for each method that the interface specifies. If the class doesn't have every method listed in the interface exactly then the compiler will complain that it does not fully implement the interface.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.