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?

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.