java programs

Interview Questions on Polymorphism in java

1. What is polymorphism in java ?

  • The word polymorphism means that occurring many forms.
  • In Java polymorphism is an OOPS concept.
  • The ability of an object to have many different forms.
  • Polymorphism happens in java when parent class reference is holding child class object.
  • In java, polymorphism can be supported via method overloading, method overriding and inheritance. 
2. Different types of polymorphism in java ?
  • There are two different types of polymorphism available in java.
    • Static binding or compile time polymorphism
    • Dynamic binding or run time polymorphism
3. What is mean by static binding or compile time polymorphism in java? OR What is mean by method overloading in java?
  • compile time polymorphism is also known as method overloading.
  • Method overloading happens with in a class or  in parent and child class.
  • Method overloading occurs when there are many methods exists with same name and 
    • Same method signature and different number of parameters.
    • Same signature and same number of parameters but with different type of parameters.
    • Different method signature and same or different number of parameters.
4. What is mean by dynamic binding or run time polymorphism in java? OR What is mean by method overriding in java?
  • run time polymorphism is also known as method overriding.
  • Method overriding can not happen in same class.
  • When two methods with same name and same signature in parent and child class is called method overriding.
  • So the calling of actual method can be decided by JVM during run time based on the type of object that reference hold.
If I missed anything please comment below.
All the very best!!
    Powered by Blogger.