Friday 17 March 2017

Difference between Abstract class and Interface

Abstract class is the class in which there is atleast one
abstract method.abstract method is the method which does not
have any body defined in that class.We cannot make any object of
the abstract class.So, that abstract class must be derived by
the subclass which defines all the abstract methods of the super
class.If the sub class doesnot define any abstract meth. of the
super class, then that sub class automatically becomes the
abstract class.When the sub class defines all the abs. meth.s of
the super class then we can make the object of the sub class and
access the other methods of the abs. super class.
An interface is the class that have all the methods as abs.
methods.All the instance variables of an interface must be
declared as final and static.Now we can implement this interface
in another class which must define all the methods of the
interface.Now make the obj. of the class that implemented the
interface.
Interfaces are used where we want the users to use the specified
methods only.Abstract classes are used in inheritence where
there is no need for the class to define any method which must
be defined in the sub classes.
Please the feedback for the above answer.There's too much about
the abstract class n interface so i could not write everything.I
think this must clear ur doubts.

No comments:

Post a Comment