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 uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- How to Use Updatable ResultSet in JDBC?
- What are class variables in Java?
- What are local variables in Java?
- How to Use JDBC Java to Create Table?
- Why final variable in Enhanced for Loop does not act final?