Results 1 to 2 of 2

Thread: Run - Time polymorphism with Overriden method in JAVA

  1. #1
    Join Date
    Dec 2008
    Posts
    31

    Run - Time polymorphism with Overriden method in JAVA

    Hello Friends,

    I am New to this forum as well as New to the Programming world of JAVA, I am little bit confused about how run-time polymorphism takes place in the Overridden method.It would be much more helpful for me, If anyone suggest this with an self explanatory code.Please help.

    Thanks for all those who replies.

  2. #2
    Join Date
    Nov 2008
    Posts
    43

    blush Re: Run - Time polymorphism with Overriden method in JAVA

    Hi NAYASA,

    I will like to help you,Check the solution below, this will help you to understand the Run Time polymorphism in Override method.

    class A
    {
    int num1,num2;
    void calc(int a,int b)
    {
    num1=a;
    num2=b;
    }

    void show()
    {
    System.out.println("Calling Method from A");
    }
    }

    class B
    {
    super(a,b);

    void show()
    {
    System.out.println("Calling Method from B");
    return num1*num2;
    }
    }

    class C
    {
    super(a,b)

    void show()
    {
    System.out.println("Calling Method from B");
    return num1*num2/2;
    }
    }


    class override{

    public static void main(String args[])

    A a = new A();
    B b = new B();
    C c = new C();

    A ref = new A();

    ref =b;
    ref.show();
    }

Similar Threads

  1. Dynamic and Static Polymorphism in Java
    By Ardent in forum Software Development
    Replies: 4
    Last Post: 19-08-2010, 03:37 PM
  2. Inheritance and polymorphism in static method
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 11:46 AM
  3. Runtime polymorphism Vs Compile time polymorphism
    By Owen Fernandes in forum Software Development
    Replies: 4
    Last Post: 03-02-2010, 11:06 AM
  4. Is java supports polymorphism?
    By beelow in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 11:30 AM
  5. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,066,075.99030 seconds with 17 queries