Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Jun 2014, 12:11 AM   #1
Warrior Member
 
Join Date: 2014
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default
java
Share on: 
fb share twitter share gplus share more share

what is the real meaning of polymorphism in java???
someshets is offline  
Unread 21st Jun 2014, 04:59 PM   #2
Programmer
 
Join Date: 2014
Location: South Carolina, USA
Posts: 25
Thanks: 12
Thanked 10 Times in 5 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Polymorphism is a very general programming concept that is employed in many modern programming languages including C++, Java, Python, PHP, and more.

The word itself is a hybrid of "poly" (many), and "morph" (form) -- put them together, and you get "multi-form-ism." In reality, this isn't far off; roughly speaking, polymorphism refers to treating a programming construct (such as an object, a variable, a type, or a function) as if it has multiple "forms" or "types."

This comes up everywhere in many programming languages. Here are a few examples of polymorphism, with a bias towards Java (since that's what you titled your thread).

Functional overloading is a type of polymorphism. "Functional overloading" is the process of creating multiple functions that have the same name, but a different number of arguments. So, for example, I might want to make two different functions to print out a person's name, depending on whether they provided one name or two:
Code:
void printName(String name)
{
    System.out.printf(name);
}
void printName(String first, String last)
{
    System.out.printf(first + " " + last);
}
This is an example of polymorphism, because the function printName() has two different "forms."

Another example of polymorphism is parametric polymorphism. "Parametric polymorphism" occurs when a programmer would like to pass a variable as a parameter to a function without specifying the variable's type. In Java, this is handled by the "generic" keyword. This is an example of polymorphism because the parameter that is sent to the function could be any type, or "form."

Finally, one last example of polymorphism in Java is may be referred to as inheritance method polymorphism, and occurs within a class inheritance model. For example, a programmer may have a base class Animal with a method talk(). Next, the programmer implements two classes Bird and Dog that are derived from the Animal class. Thus, Birds and Dogs are both Animals. However, birds and dogs do not talk the same, so when we call Bird::talk(), we expect different behavior than when we call Dog::talk(). Perhaps when a Bird talks, we expect "tweet" to be printed, but when a Dog talks, we expect "woof" to be printed. This is an example of polymorphism, because the method Animal::talk() has different functionality based on whether the Animal that is talking is a Dog or a Bird.
onsmith is offline  
Unread 4th Jul 2014, 08:20 AM   #3
Warrior Member
 
Join Date: 2014
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Or simply - it allows you to override a function to have a different behavior from the original.

Polymorphism is one of the pillars of Object Oriented Programming.
pphillips001 is offline  
Unread 9th Jul 2014, 01:30 AM   #4
Warrior Member
 
JohnBrower's Avatar
 
Join Date: 2014
Location: San Diego, USA
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Polymorphism is an object oriented concept widely used in Java. In Java polymorphism is supported along with Abstraction, Encapsulation and Inheritance. Polymorphism is something which can take many forms. Polymorphism in Java is the use of common interface instead of concrete implementation while writing code.

JohnBrower is offline  
Unread 25th Jul 2014, 03:29 AM   #5
Warrior Member
 
Join Date: 2014
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Polymorphism is one object which have many forms.
For ex-
public interface Vegetarian{}
public class Birds{}
public class Parrot extends Birds implements Vegetarian{}

Now, the Parrot class is considered to be polymorphic since this has multiple inheritance. Following are true for the above example:

A Parrot IS-A Bird

A Parrot IS-A Vegetarian

A Parrot IS-A Parrot

A Parrot IS-A Object

now if we make a object of Parrot class then the following declarations are legal

Parrot d = new Parrot();
Birds a = d;
Vegetarian v = d;
Object o = d;

all the reference variables refer to same Parrot object in the heap
ashish sharma is offline  
Unread 19th Aug 2014, 12:05 AM   #6
Warrior Member
 
Join Date: 2014
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Polymorphism is the ability of an object to take on many forms.
Polymorphism is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations.
There are two types of polymorphism in java
  • Runtime Polymorhism( Dynamic polymorphism)
  • Compiletime Polymorphism (static polymorphism).


wilsonmarcial is offline  
Unread 30th Sep 2014, 09:40 PM   #7
HyperActive Warrior
 
Member8200's Avatar
 
Join Date: 2008
Posts: 310
Thanks: 10
Thanked 39 Times in 35 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

Polymorphism

The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages.

This principle can also be applied to object-oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.

source: Polymorphism (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
Member8200 is offline  
Unread 14th Oct 2014, 01:47 AM   #8
Banned
 
Join Date: 2014
Posts: 87
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: java
Share on: 
fb share twitter share gplus share more share

hi, Polymorphism in java is not one things it contain.because poly is taken from greek word its meaning is many so it contain many forms in one structure like abstraction,encapsulation etc.
pinkwhale is offline  
Closed Thread


Bookmarks

Tags
java


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:43 PM.