Can u write example for static polymorphism?

Showing Answers 1 - 6 of 6 Answers

Hi,

    As I know method overloading would be an example of static polymorphism and method overriding would be an example of dynamic polymorphism. Because in static polymorphism compiler knows very well which method has to call and checks the syntax of methods which has been overridden because at compile time it can't determine which method would be called becz it determined at runtime so we call it dynamic polymorphism.

                          I have written according to my knowledge if i am wrong then please reply.

                                        Abhishek(Sharad)

  Was this answer useful?  Yes

sirisha

  • Dec 19th, 2006
 

Hi all,

         what my frnd Abhishek has said is absolutely true.here goes the example

               class StaticPloymorphism
{
 
 public int sum(int a,int b)
 {
  return (a+b);
 }

 public float sum(float a, float b)
 {
  return (a+b);
 }

 
}
class Ploy
{
 public static void main(String[] args)
 {
  int a;
  int b;
  int c;
  float a1;
  float b1;
  float c1;
  a=1;
  b= 2;
  a1=2.31f;
  b1=3.14f;

  StaticPloymorphism obj = new StaticPloymorphism();
  c = obj.sum(a,b);
  System.out.println("SUM OF INTEGERS= "+c);
  c1 = obj.sum(a1,b1);
  System.out.println("SUM OF FLOAT= "+c1);
 }
}

  in static polymorphism the method signature changes whereas the method name remains the same

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions