Reputation: 353
What does this exactly mean in Java?
Interface defines a contract for implementing classes
Upvotes: 3
Views: 473
Reputation: 25
In interface you simply declare the members(say methods). For example
public Interface Product{
protected void getProduct();
protected void getProductId();
}
Whereas in a class you can implement the above interface and can define these methods...
public class ProductClass implements Product{
protected void getProduct()
{
System.out.println("Product is: ");
}
protected void getProductId()
{
System.out.println("Product Id is: ");
}
}
So you can see the methods declared in interface are defined in the class. Basically, you can say that interface just provides the blueprint but class actually does the whole work.
Upvotes: 0
Reputation: 245439
It means that by implementing an interface, the class agrees to implement all of the functionality specified by the interface.
Upvotes: 8