The Artima Developer Community
Sponsored Link

Java Buzz Forum
Difference between Polymorphism and Inheritance in Java and OOP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Difference between Polymorphism and Inheritance in Java and OOP Posted: Apr 1, 2014 7:01 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Difference between Polymorphism and Inheritance in Java and OOP
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Programmers often confused among different object oriented concepts e.g. between Composition and Inheritance, between abstraction and encapsulation and some-time between Polymorphism and Inheritance. In this article, we will explore third one, Polymorphism vs Inheritance. Like in real world, Inheritance is used to define relationship between two classes. It's similar to Father-Son relationship. In object oriented programming, we have a Parent class (also known as super class) and a Child class (also known as sub class). Similar to real world, Child inherit Parents qualities, e.g. it's attribute, methods and code. Inheritance is actually meant for code-reuse. Child can reuse all the codes written in Parent class, and only write code for behaviour which is different than parent. Though it’s possible to restrict something to parent itself by using private and final keyword in Java. On the other hand, Polymorphism is an ability of Object to behave in multiple form. For example a Parent variable can hold reference of either a Parent object or a Child object, so when you call a virtual method on Parent's object, it may go to child's method depending upon which kind of object it is pointing at runtime. This is known as Polymorphism, and one of the most popular form of Polymorphism is method overriding in Java. By the way, If you look closely they are actually related to each other, because its Inheritance which makes Polymorphism possible, without any relationship between two class, it's not possible to write polymorphic code, which can take advantage of runtime binding of different objects. You cannot use Polymorphism on something which is not inherited by Child class e.g. private method can't be overridden in Java. Let's take an example to understand difference between Polymorphism and Inheritance in Java more closely.
Read more »

Read: Difference between Polymorphism and Inheritance in Java and OOP

Topic: Why Hire Older Engineers Previous Topic   Next Topic Topic: The Way of the Pro

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use