• 1 reply
  • Latest Post - ‏2011-06-28T07:29:57Z by phalgunkumar
1 Post

Pinned topic polymorphism

‏2011-06-23T14:31:46Z |
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?
Updated on 2011-06-28T07:29:57Z at 2011-06-28T07:29:57Z by phalgunkumar
  • phalgunkumar
    1 Post

    Re: polymorphism

    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