What is the difference between an abstract class and an interface?
An abstract class can be partly finished so that the child class can fill in appropriate missing info. An interface simply demands that an implementing class to implement a certain behavior, leaving it up to the implementing class as to how this is to be done. Neither interface or abstract classes can be instantiated.
What is the defferent between them?
- An abstract class can contain both non-abstract methods (methods with a body) and abstract methods (methods without a body). An interface only contains abstract methods.
- A class can implement multiple interfaces, but can only subclass one abstract class.
- An abstract class can have instance variables and instance initializers. An interface cannot. Any variables defined in an interface are implicitly public, static, and final (the variables of an interface are final they must be initialized).
- An abstract class can define constructor. An interface cannot.
- An abstract class can have public or protected methods. An interface can have only public methods.
- An abstract class inherits from Object and includes methods such as clone() and equals().
Most Recent java Faqs
- How to avoid an java.util.ConcurrentModificationException with ArrayList?
- How to convert a given array to a list in Java?
- How to make Java objects eligible for garbage collection?
- What are local variables in Java?
- What are instance variables in Java?
- How many backslashes?
- What are class variables in Java?
Most Viewed java Faqs
- How to use HttpURLConnection POST data to web server?(24746)
- What is runtime polymorphism in Java?(18328)
- How to add BASIC Authentication into HttpURLConnection?(16088)
- What is String literal pool?(14754)
- Can the run() method be called directly to start a thread?(13991)
- What does Class.forname method do?(10593)
- Can transient variables be declared as 'final' or 'static'?(10446)