IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

whats the difference between polymorphism and inheritence

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Messages: 228

whats the difference between polymorphism and inheritence,they tend seem to look same to me?

www.lifesbizzare.blogspot.com
Siddhesh Deodhar
Greenhorn

Joined: Mar 05, 2009
Messages: 23

check this out

Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd (SCJP 6 )
C Shinde
Ranch Hand

Joined: Oct 22, 2009
Messages: 39

Yes they are same as Inheritance in the means to achieve Polymorphism.

Regards,
Chetan Shinde
Deepika Singh
Greenhorn

Joined: Oct 10, 2008
Messages: 21

An ideal instance of using Inheritance would be when you want to create an entirely new class, but wish to borrow a group of existing attributes or methods resident in an existing Abstract or super Class, instead of re-inventing the wheel. If you had an Abstract Class Carnivore and wanted to create a subclass Cat, you could instantly inherit all the methods that were common in Carnivore that applied to Cat without writing new code.

Polymorphism could be best applied when you had an existing SubClass that you wanted to modify or add a feature that could borrow a method that existed in a higher class. Take the Cat subclass, which inherited attributes from Carnivore, and you wanted to add the method Stalk, which would generically describe how a carnivore approaches its prey. However its implementation in Cat would detail the stealth it uses that are unique to a Cat.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
The most intelligent Java IDE

.