472,090 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,090 software developers and data experts.

Polymorphism in Java

What is the difference between static and dynamic Polymorphism in java?
Jan 2 '16 #1
3 12318
zmbd
5,501 Expert Mod 4TB
Vikas Rana, is this a homework question?
Such threads are usually closed when found.
-z
Jan 2 '16 #2
Ishan Shah
47 32bit
Static polymorphism is a type of polymorphism, which collects data to call a method during compilation. Whereas dynamic polymorphism is a type of polymorphism that collects information for calling a method at the time of execution. So that's the main difference between static and dynamic polymorphism.
Feb 12 '21 #3
vipulguptaseo
3 2Bits
Polymorphism is a fundamental concept in object-oriented programming (OOP) and refers to the ability of an object to take on many forms. In Java, polymorphism is achieved through method overloading and method overriding.

Method overloading allows multiple methods to have the same name but with different parameters. When a method is called, Java determines which version of the process to execute based on the number and types of arguments passed to it.

Here is an example of method overloading in Java:
public class MyClass {

public void myMethod(int num) {

System.out.println("This is an integer: " + num);

}



public void myMethod(String str) {

System.out.println("This is a string: " + str);

}



public void myMethod(double dbl) {

System.out.println("This is a double: " + dbl);

}

}

In this example, the `myMethod` method is overloaded three times with different parameter types. When called, the appropriate version of the method is executed based on the argument passed.

Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass. This allows the subclass to inherit the methods of the superclass while still being able to customize their behavior.
1 Week Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

54 posts views Thread by Jerry | last post: by
13 posts views Thread by Gurtaj | last post: by
3 posts views Thread by Mayer Goldberg | last post: by
7 posts views Thread by rashkatsa | last post: by
12 posts views Thread by Steve Jorgensen | last post: by
6 posts views Thread by Mike | last post: by
6 posts views Thread by G.Ashok | last post: by
11 posts views Thread by chsalvia | last post: by
4 posts views Thread by =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.