What is an Interface and What is an Abstract class? (java)
Abstract class: is an incomplete class. This is a kind of a house under construction which is not yet completed.
Since abstract classes are incomplete, you can't create any object for that class. It doesn't make any sense to create object.
But any one can inherit abstract classes to give extra definition for that class to make it more concrete.
Abstract class can contain 0 or more number of abstract methods. If it is having at least one abstract method, then
we have to make that class as abstract class.
A class will become abstract class, if we know only partial implementation of that class.
Abstract class can contain method definitions.
Interface: as name suggests, it is an interface between your class and out side world.
interfaces can contain only constants, method declarations, and nested types. It can't contain method definitions.
Just like an abstract class, you can't create object for an interface.
You can imagine interface just like a header file in c program. It tells what all the functionalities supported by your interface.
Back To Top