File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes means Polymorphic method call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "means Polymorphic method call" Watch "means Polymorphic method call" New topic
Author

means Polymorphic method call

Shalini Gupta
Greenhorn

Joined: Aug 06, 2008
Posts: 11
What is the meaning of Polymorphic method call. Is it the way when super class reference contains sub class object and we try to call overridden method through that ?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Yes that would be polymorphism.

Please change your display name to ensure that you have a valid first and last name


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Shalini Gupta
Greenhorn

Joined: Aug 06, 2008
Posts: 11
yes I will do that. Actaully it is Shalini Gupta
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well there are two type of Polymorphism...
One is static and the other is dynamic.

A static polymorphism is implemented by overloading.

Dynamic polymorphism is implemented by the same way that you said. You create an instance or reference of a super class and initialize it with a sub class. Then you call a method that is overriden in the sub-class. The method which is actually called at run-time is dependent on the actual type of the object stored in reference.

This is an example-


If you execute this program like this
java MainClass 1
The output will be Derived1

If you execute this program like this
java MainClass 2
The output will be Derived2

If you execute this program with any other argument
java MainClass me
The output will be Base

So the call to the display method will be resolved at runtime.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

"Shalini Gupthaaaaaa", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: means Polymorphic method call