Java Polymorphism

Describe why Java supports only runtime polymorphism?

Questions by tariqueanwer   answers by tariqueanwer

Showing Answers 1 - 9 of 9 Answers

Polymorphism means when an entity behaves differently depending upon the context its being used.Moreover In other words Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. Means, polymorphism allows you define one interface and have multiple implementation. That being one of the basic principles of object oriented programming.

The method overriding is an example of runtime polymorphism. You can have a method in subclass overrides the method in its super classes with the same name and signature. Java virtual machine determines the proper method to call at the runtime, not at the compile time.

And when java was being developed they removed all hazziness of C++ or things that create a lot of confusion like removed pointer an memory allocationbut still kept things same as c++ so that one migrating from C++ to java doesn't gets a shock that one needs to learn new things. Hence, they decoded that every function whould get resolved at runtime only.

tarun23

  • Nov 1st, 2009
 

The three ways of polymorphism in Java are method overloading, method overridding and method overridding by extending an class. All these results come true when we run our class which is overloading or overidding any method since we run methods at runtime. In this way Java supports polymorphism at runtime.

  Was this answer useful?  Yes

Real polymorphism has to be at run time. Think of this scenario, Java has exposed JDBC drivers interface and you load the driver class at runtime. Using the same code you can connect to any JDBC compliant database where the actual database to be connected may be supplied by user at runtime. How such a functionality can be supported at compile time?

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions