Is Method overloading is also known as static polymorphism?

Iam just newbie to java In the below code I have oveloaded print method between two different classes

Based on object at runtime only corresponding print method will be executed.If my understanding is right then how can we say method overloading is considered to be static ploymorphism

class Parent { private int arg; public void print(int arg) { this.arg=arg; System.out.println(arg+"printed"); } } class Child extends Parent{ private String arg; public void print(String arg) { this.arg=arg; System.out.println(arg+"printed"); } public static void main(String[] args) { // TODO Auto-generated method stub Parent p1=new Parent(); Child ch=new Child(); p1.print(1); ch.print("String"); } }

Please clarify me.Thanks in advance

-------------Problems Reply------------

Try reading this , may clear your doubts about how polymorphism works Can't access object in the array java

Yes, this is compile-time(static) polymorphism - given that you could write code such as :

Child ch=new Child();

Category:java Views:2 Time:2019-03-02
Tags: java

Related post

  • Method overloading as a static polymorphism in C# 2011-03-26

    How method overloading is considerd as a static polymorphism in c#? --------------Solutions------------- According to google (if you type in "define static polymorphism"): Polymorphism implemented at compile-time; generics. At compile time it is know

  • Class design: allow a class to be used both as an object and also supply public static methods 2009-09-05

    I have a silly, little class "FileSystemSize" which can be used both as an object and also via public, static methods. The output is similar, but not identical in each case. The class was intially static, but I added the possibility to initialize it

  • Method overload resolution using dynamic argument 2011-08-26

    This may have been answered before. I see many "dynamic method overload resolution" questions, but none that deal specifically with passing a dynamic argument. In the following code, in Test, the last call to M cannot be resolved (it doesn't compile)

  • Method Overloading. Can you overuse it? 2008-10-29

    What's better practice when defining several methods that return the same shape of data with different filters? Explicit method names or overloaded methods? For example. If I have some Products and I'm pulling from a database explicit way: public Lis

  • method overloading and polymorphism 2009-07-28

    I'm writing a .NET web application in which administrators can customize the various data entry forms presented to their users. There are about half a dozen different field types that admins can create and customize (i.e. text, numeric, dropdown, fil

  • Method Overloading with Types C# 2009-10-22

    I was wondering if the following is possible. Create a class that accepts an anonymous type (string, int, decimal, customObject, etc), then have overloaded methods that do different operations based on the Type. Example class TestClass<T> { pub

  • Can Visual Studio's C# intellisense be given a hint to display a certain method overload first? 2009-12-15

    I have two methods that are overloads of each other public class Car { public int GetPrice(string vinNumber) { string make = Database.GetMake(vinNumber); // expensive operation string model = Database.GetModel(vinNumber); // expensive operation int y

  • Is Method Overloading considered polymorphism? 2010-03-08

    Is Method Overloading considered part of polymorphism? --------------Solutions------------- No, overloading is not. Maybe you refer to method overriding which is indeed part of polymorphism. To further clarify, From the wikipedia: Polymorphism is not

  • method overloading vs optional parameter in C# 4.0 2010-07-23

    This question already has an answer here: Should you declare methods using overloads or optional parameters in C# 4.0? 8 answers which one is better? at a glance optional parameter seems better (less code, less XML documentation, etc), but why do mos

  • C++ methods overload in python 2010-08-13

    suppose a C++ class has several constructors which are overloaded according the number and type and sequences of their respective parameters, for example, constructor(int x, int y) and constructor(float x, float y, float z), I think these two are ove

  • What is the use of Method Overloading in Java when it is achieved by changing the sequence of parameters in the argument list? 2011-01-07

    I was reading a Java training manual and it said that Method Overloading in Java can be achieved by having a different argument list. It also said that the argument list could differ in (i). Number of parameters (ii). Datatype of parameters (iii). Se

  • Method overloading in Java 2011-01-28

    import java.lang.Math; class Squr { public static void main () { Squr square = new Squr(); System.out.println ("square root of 10 : " + square.mysqrt(10)); System.out.println (" Square root of 10.4 : "+ square.mysqrt(10.4)); } int mysqrt ( int x) { r

  • EF generic method overloading 2011-04-05

    I'd like make possible a generic method overload. Since I need to create an ObjectSet<..> without knowing the generic type contained in, I wold build something like this: public IQueryable<T> MyMethod<T>() where T : class, (IMyFirst

  • Method Overloading Versus Optional Parameters 2011-05-10

    I seem to recall reading there was an important difference between method overloading (and constructor chaining) and optional parameters in C# 4.0, but I haven't been able to locate anything acknowledging any difference. Are there any important diffe

  • PHP 5.3 method overloading (like in Java) 2011-07-05

    In Java, we have a method overloading feature that's very useful for Singletons. For example, i have two different getInstance methods, public static, that behave differently based on the parameters received: public static Currency getInstance(String

  • method overloading & polymorphism - what is a cleaner way to do this? 2011-08-05

    Check the following code sample: public class Test { private void process(Instance1 obj) { System.out.println("Process Instance 1"); } private void process(Instance2 obj) { System.out.println("Process Instance 2"); } /* COMMENT THIS OUT - I DON'T HAV

  • Why doesn't ruby support method overloading? 2012-02-21

    Instead of supporting method overloading Ruby overwrites existing methods. Can anyone explain why the language was designed this way? --------------Solutions------------- Method overloading can be achieved by declaring two methods with the same name

  • Choosing the Most Specific Method - Tricky Method Overloading? 2012-10-28

    I have gone through this link; but I am getting confused with the following sample code:- public class NullTest { public static void method(Object obj){ System.out.println("method with param type - Object"); } public static void method(String str){ S

  • What is the reason behind "non-static method cannot be referenced from a static context"? 2008-11-14

    This question already has an answer here: non-static variable cannot be referenced from a static context 9 answers The very common beginner mistake is when you try to use a class property "statically" without making an instance of that class. It leav

  • Method Overloading Cost In .Net 2009-02-26

    Is there a cost associated with overloading methods in .Net? So if I have 3 methods like: Calculate (int) Calculate (float) Calculate (double) and these methods are called at runtime "dynamically" based on what's passed to the Calculate method, what

  • Method overloading in Objective-C? 2010-02-18

    As far as my knowledge, Objective-C does not support method overloading. What can be the alternative for this in Objective-C? Or should I always use different method name? --------------Solutions------------- Correct, objective-C does not support met

  • How to make __set also work for static operation in PHP? 2010-03-12

    When I call self::$parameter = 1; the __set is not called. Is there a way to workaround? --------------Solutions------------- From the manual: Property overloading only works in object context. These magic methods will not be triggered in static cont

  • non static method cannot be referenced from a static context 2010-04-22

    This question already has an answer here: What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate] 13 answers First some code: import java.util.*; //... class TicTacToe { //... public static void main (Str

  • Java method overloading + double dispatch 2010-05-08

    Can anybody explain in detail the reason the overloaded method print(Parent parent) is invoked when working with Child instance in my test piece of code? Any pecularities of virtual methods or methods overloading/resolution in Java involved here? Any

Copyright (C), All Rights Reserved.

processed in 0.112 (s). 11 q(s)