Any class that implements an interface must satisfy 2 conditions:
- It must have the phrase "implements Interface_Name" at the beginning of the class definiton.
- It must implement all of the method headings listed in the interface definition.
public interface Dog
{
public boolean Barks();
public boolean isGoldenRetriever();
}
Now, if a class were to implement this interface, this is what it would look like: public class SomeClass implements Dog
{
public boolean Barks{
// method definition here
}
public boolean isGoldenRetriever{
// method definition here
}
}
Now that we know the basics of interfaces and abstract classes, let’s get to the heart of the question and explore the differences between the two. Here are the three major differences: