an abstract class is just a outline of the entire class. u can have only method name inside it. u can't create objects for them. a abstract class should always be inherited. where as a inteface is a collection or a group of empty methods.
An abstract class is a class which may or maynot consist of the abstract methods while an interface must have all the functions as abstract.
the abstract class with all the functions as abstract must be defined as an interface.
Abstract class can (or not ) have methods in it and it has no use in instantiating it since it has no meaning in instantiation.
It has to be inherited for use .
You need to INHERIT to use an abstract class.
You can have a variable in Abstract class. ( a silly difference )
Basically u use an abstract class when you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.
Interface - group of related methods with empty bodies .
You need to IMPLEMENT to use an interface.
I dont think you can have a variable in a interface.
When you want a few classes to use a few methods which you dont want to be included in the class ,then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface. But the problem with the interface is that, u have to implement all the methods defined in the interface , even if you dont need some of them.
An abstract class is a class which may or maynot consist of the abstract methods while an interface must have all the functions as abstract.
the abstract class with all the functions as abstract must be defined as an interface.
Abstract class can (or not ) have methods in it and it has no use in instantiating it since it has no meaning in instantiation.
It has to be inherited for use .
You need to INHERIT to use an abstract class.
You can have a variable in Abstract class. ( a silly difference )
Basically u use an abstract class when you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.
Interface - group of related methods with empty bodies .
You need to IMPLEMENT to use an interface.
I dont think you can have a variable in a interface.
When you want a few classes to use a few methods which you dont want to be included in the class ,then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface. But the problem with the interface is that, u have to implement all the methods defined in the interface , even if you dont need some of them.
No comments:
Post a Comment