health

Technology

business posts

Powered by Blogger.

Total Pageviews

Name

your name

Email *

Your Email

Message *

your message

Followers

Translate

Pages

Pages

Java interface versus abstract class

 An interface differs from an abstract class because an interface is not a class. An interface is essentially a type that can be satisfied by any class that implements the interface.
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.
This is what an interface called "Dog" would look like:
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: 

No comments: