Skip to content

TechXcel.com - provides technical excellence...

Narrow screen resolution Wide screen resolution Increase font size Decrease font size Default font size default color orange color green color
You are here: Home
What is Polymorphism? PDF Print E-mail
(0 votes)
Written by Mukesh Ranjan   
Wednesday, 23 May 2007


What is Polymorphism?


Polymorphism means "any forms."

In OOPS, it refers to the capability of objects to react differently to the same method. Polymorphism can be implemented in the Java language in the form of multiple methods having the same name. Java code uses a late-binding technique to support polymorphism; the method to be invoked is decided at runtime.

TYPES : Overloading and Overriding


Overloading

Methods having same name but different argument lists.Argument may differ in types or number or both.


Overriding

A subclass can redefine a method that it inherits from its super class.The overriding method must have the same name, arguments, and return type as the overridden method.The overriding method cannot be less public than the overridden method. The overriding method should not throw new or broader checked exceptions that are not declared by the original method. In the following example, the overridden version of the print() method is invoked because the invoking object is an instance of the derived class:

class Base  {
               void print()    {
               System.out.println("Base");
               }
  }          
  class Derived extends Base  {
               void print()    {
                System.out.println("Derived");
                }
               public static void main(String args[])      {
                           Base obj = new Derived();
                           obj.print();// "Derived" is printed   
               }
  }


To invoke the superclass version of an overridden method from the subclass, use super.methodName(). In the above example, the subclass can use the functionality of the superclass print() method by calling super.print(). Methods declared as final cannot be overridden by subclasses. Even though constructors can be overloaded, they cannot be overridden because they are not inherited.


More info

For more java related stuff visit Mukesh Ranjans site here

submit your Article, Tutorials or FAQs

Hello... if you are interested to submit your Article, Tutorials or FAQs on TechXcel.com - provides technical excellence... mail us at This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Comments (0)Add Comment

Write comment
You must be logged in to a comment. Please register if you do not have an account yet.

Copyright 2007. All Rights Reserved.
busy




Reddit!Del.icio.us!Google!Live!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Spurl!Wists!Simpy!Newsvine!Blinklist!Furl!Fark!Blogmarks!Yahoo!Smarking!Netvouz!Shadows!
RawSugar!Ma.gnolia!PlugIM!Squidoo!BlogMemes!FeedMeLinks!BlinkBits!Tailrank!linkaGoGo!
Last Updated ( Wednesday, 23 May 2007 )
 

Who's Online

We have 1 guest online

User Login

PayPal Donation

Enter Amount:

Syndicate

TechXcel's Friends

Tutorials Garden
Wicolorz
pixel2life

Text Link Add

Statistics

Members: 276
News: 60
Web Links: 6
Visitors: 348405

Google Seach

Google AdSense

TechXcel Referrals

TechXcel's Sponcer...