what is the ipmortants of polymorphism,whats the different between Abstract method/class and Interface?
how to decide on when to use interface over abstract?
Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
phalgunkumar 270003HAWF1 Post
Re: polymorphism2011-06-28T07:29:57ZThis is the accepted answer. This is the accepted answer.Polymorphism : Showing one thing in different forms (in general wordsd). But in java we have two types of polymorphism. 1) Static(method overloading) 2) Dynamic (Method Overrriding.
Method Oveloading : With same method name we will write two or more mthods in a single class (diiferentiating type of parameters and no. of parameters).
ex: void add(int a, int b) and void add(double a, double b) etc.
Method Overriding : With same method siganture we will write one more mthod in child classes. Based on the reference it will called dynamically.
Abstarct Method : A method which is not having body, we will just declare it. Defination will be in implemented or extended class
Abstarct Class : A class which has atleast on abstract method in it.
Interface : All the methods by default abstrat and variables by defauls final.
Difeerence Between Abstract Class and Interface : We will go for Abstarct Class when we need partial implementation left to child class
We will go for Interface when we need full implementation left to implemented class