Originally posted by Pree ty mark:
what is uses or advantages of Inheritances and polymorphism in oops.
Polymorphism is a tool for decoupling. Imagine the following simple example:
This code has two responsibilities: knowing *what* to print ("hello world") and *where* to print it (System.out).
Now, if we don't want the code to know about *where* to print, we can make use of polymorphism:
This code doesn't know about *where* to print - all it knows is that it gets an object which can print to *somewhere* (could be the console, a file, a database, in memory etc.).
http://www.objectmentor.com/resources/articles/dip.pdf shows this on a more elaborate example.
In statically typed languages like
Java, inheritance is used to implement polymorphism. In dynamically typed ones (Smalltalk, Ruby etc.), inheritance is just a way to share common code between classes.
Did that help?