473,699 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Polymorphism in Java

3 New Member
What is the difference between static and dynamic Polymorphism in java?
Jan 2 '16 #1
4 18639
zmbd
5,501 Recognized Expert Moderator Expert
Vikas Rana, is this a homework question?
Such threads are usually closed when found.
-z
Jan 2 '16 #2
Ishan Shah
47 New Member
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
22 New Member
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.prin tln("This is an integer: " + num);

}



public void myMethod(String str) {

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

}



public void myMethod(double dbl) {

System.out.prin tln("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.
Mar 9 '23 #4
Nikhilesh10
14 New Member
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.
Mar 20 '23 #5

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

Similar topics

54
8965
by: Jerry | last post by:
What are the advantages and disadvantages of using Object Oriented PHP vs Java?
13
7887
by: Gurtaj | last post by:
Hello! I am working with PHP and MySQL in a proyect with some partners of our university, and we are thinking about building some classes and use inheritance and polymorphism. The problem is that we are not sure of PHP implementing polymorphism and we couldn't find info about it. I will really appreciate if someone could give us some recommendations about some books to read about it and/or pages to look for some info. Thanks for all.
3
2136
by: Mayer Goldberg | last post by:
Can someone please explain the motivation behind the following restriction in the language: I define an interface and two classes implementing it: public interface InterA {} public class B implements InterA {} public class C implements InterA {}
7
4544
by: rashkatsa | last post by:
Hi all ! I have written a little module called 'polymorph' that allows to call different methods of a class that have the same name but that have not the same number of arguments. *args are supported. You could find the module attached to this message. As in python, you could not define two method with same name (the second one override the first one), i have choosen to design it through private prefix '__' (defined method names and...
12
7049
by: Steve Jorgensen | last post by:
The classing Visual Basic and VBA support for polymorphism, let's face it, is a bit on the weak side, and built-in support for inheritance is non-existent. This little essay is about some patterns I've ended up using successfully for certain kinds of inheritance and polymorphism, and some that have not worked out so well. Let's start with obvious things that turn out not to work well: 1. Use interface classes and "Implements" for...
6
11457
by: Mike | last post by:
Attached below is a file that implements polymorphism in C. It's loosly based on the way Miro Samek describes it (http://www.embedded.com/97/fe29712.htm). I found the article a little confusing so I made some changes and came up with wat's below. It appears to work, but I've written plenty of programs before that seemed to work, but didn't. Anyone willing to take a look, and check for correcness? I would also love to hear suggestions...
6
1820
by: G.Ashok | last post by:
Hi, Does anybody know how Multiple polymorphism can be done in VB.NET or DOT doesn't support it? Is there any third party extensions available like for Java to do this? Regards, ....Ashok ------------------------------------------------------------------------ "It is beautiful for an engineer to shape and design the same way
11
2971
by: chsalvia | last post by:
I've been programming in C++ for a little over 2 years, and I still find myself wondering when I should use polymorphism. Some people claim that polymorphism is such an integral part of C++, that anybody who doesn't use it might as well just program in plain C. I totally disagree with this, because I think C++ has a lot of great features apart from polymorphism, such as the ability to organize code into classes, code reuse through...
4
3770
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, (sorry to begin with Java in a Python list ;-) in Java, when I want to pass input to a function, I pass "InputStream", which is a base class of any input stream. In Python, I found that "file" objects exist. While specifying argument types in Python is not possible as in Java, it is possible to check whether an object is an instance of some class and that's what I need - I need to check if an argument is a "file"-like object,...
0
3895
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented programming but on Java programming but I will cover all the important aspects of object oriented programming as Java has full support for object-oriented programming even though it is not a fully object-oriented language (in the sense that you can write...
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8633
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8902
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7787
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.