Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi Question

 
Fred Man
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is What is polymorphism and why is it important in Object Oriented programming.?

Please help
 
Fred Man
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also can you give example of code
 
Gaurav Chhabras
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all please keep this thing in your mind that

Write some meaningful subject in the subject line so that one can see the subject and come to know that what type of question it contains

This is Ranch policy , so please follow this.

Now , regarding polymorphism, you can understand with the help of methord overriding. In this we have two different classes but some methords are with same name.

Like -:

class A
{
void test()
{
System.out.println("I am in Class A");
}
}

class B extends A
{
void test()
{
System.out.println("I am in Class B");
}
}

Now there are two classes A and B.Both have one function with same name i.e test(). Now at runtime it will depend on the Object that test() methord of which class will be get called.

Thanks
Regards
Gaurav
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at How My Dog Learned Polymorphism by Kathy Sierra.
 
Fred Man
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah sorry about not mentioning the title of the topic in the suject, but you did not answer my secoud part of the question, y do programmers use this

thank you
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the story.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic