Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 69
Is java supports polymorphism?

Hi friends,

I just started the java programming. I want to know that , Is java supports to the polymorphism?

Can you explain what is polymorphism and how it can be implemented in JAVA language with suitable example.

Your help greatly appreciated...
Reply With Quote
  #2  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Is java supports polymorphism?

Hi,

Obviously java supports polymorphism. Because JAVA is fully object oriented language.

Below details will give you the idea about polymorphism:

Polymorphism gives the ultimate flexibility in extensibility. Polymorphism describes a situation in which one name might refer to other different methods.

Basically in java supports two type of polymorphism:
1. overloading type.
2. overriding type.

When you override any methods in java, java determines the proper methods to call at the run time.

Overriding occurs when a class method has the same name and signature as a method in base class it is called as overriding.

Example of Overloading:
Quote:
Class Book{
String title;
String publisher;
float price;
setBook(String title){
}
setBook(String title, String publisher){
}
setBook(String title, String publisher,float price){
}
}
Example of Overriding:

Quote:
Class Book{
String title;
String publisher;
float price;
setBook(String title){
}
setBook(String title, String publisher){
}
setBook(String title, String publisher,float price){
}
}
Reply With Quote
  #3  
Old 19-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Is java supports polymorphism?

Polymorphism is the one of the basic feature of the OOP(Object Oriented Programming).

And I think you are not aware that java is object oriented language,So there is no doubts that java supports polymorphism concept.

I don't have that much knowledge about this concept But I know that "polymorphism means when an entity behaves entirely different depends upon the context in which it is being used."
Reply With Quote
  #4  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Is java supports polymorphism?

Hello friends,

Polymorphism stands for Poly(Many) + morhism(foru) which means that multiple forms.
It is an Object oriented language feature through which multiple things can be done with only one program code by changing its input parameters only.

Java supports polymorphism concept through method overloading and method overriding.

refer following example:

Quote:
public class MountainBike extends Bicycle{
private String suspension;

public MountainBike(int startCadence, int startSpeed, int startGear, String suspensionType){
super(startCadence, startSpeed, startGear);
this.setSuspension(suspensionType);
}

public String getSuspension(){
return this.suspension;
}

public void setSuspension(String suspensionType){
this.suspension = suspensionType;
}

public void printDescription(){
super.printDescription();
System.out.println("The MountainBike has a " + getSuspension()
+ " suspension.");
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Is java supports polymorphism?"
Thread Thread Starter Forum Replies Last Post
Is Nokia N9 supports Java MIDP 2.1? Bhuvnesh 1 Portable Devices 4 21-01-2012 12:32 AM
Dynamic and Static Polymorphism in Java Ardent Software Development 4 19-08-2010 03:37 PM
Runtime polymorphism Vs Compile time polymorphism Owen Fernandes Software Development 4 03-02-2010 11:06 AM
Is Sony Ericsson K530i supports JAVA Application ? Omesh Portable Devices 2 06-06-2009 09:36 PM
Run - Time polymorphism with Overriden method in JAVA NAYASA Software Development 1 04-12-2008 07:11 PM


All times are GMT +5.5. The time now is 09:31 PM.