Showing posts with label Polymorphism. Show all posts
Showing posts with label Polymorphism. Show all posts

Sunday, November 26, 2017

OOP CONCEPTS

POLYMORPHISM
  • Ability to identify a function to run.
  • One name many forms.(some object/function behaving as many forms)

1)Compile time(Overloading)
  • Also called method and operator overloading.
  • Method with same name,but different signature,signature means:
  1.  No. of parameters
  2. Type of parameters
  3. Order of parameters

2)Run-time(Overriding)
  • Method of base class is re-defined in the derived class.
  • Method with same name,same signature and exactly the same return type.



INHERITANCE
  • Child class allows to inherit properties from its parent class(extends keyword).
  • Access only public/protected.


Multiple inheritance
  • Child class inherit properties from multiple classes.
  • Java does not allow extend multiple classes.
  • Problem with multiple inheritance: 

If multiple parents have methods with same name,then at run at run time difficult to decide for the compiler,which method to execute.

  • To overcome this problem,Java allows to implement multiple interfaces.