Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,849 questions

9,751 answers

573 users

How to overload method with diffrent data types in Java

Anker Quick Charge 3.0 63W 5-Port USB Wall Charger, PowerPort Speed 5 for Galaxy S7/S6/Edge/Plus, Note 5/4 and PowerIQ for iPhone X / 8 / 7 / 6s / Plus, iPad Pro/Air 2/mini, LG, Nexus, HTC


6 views
asked Jul 3, 2017 by avibootz
edited Jul 3, 2017 by avibootz

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public void overload(char ch) {
        System.out.println("char");
    } 
    public void overload(byte b) {
        System.out.println("byte");
    }    
    public void overload(short s) {
        System.out.println("short");
    }    
    public void overload(int i) {
        System.out.println("int");
    }
    public void overload(long l) {
        System.out.println("long");
    }
    public void overload(float f) {
        System.out.println("float");
    }
    public void overload(double d) {
        System.out.println("double");
    }    
    public void overload(boolean b) {
        System.out.println("boolean");
    } 

    public void runOverloadMethods() {
        overload('1');
        overload((byte)1);
        overload((short)1);
        overload(1);
        overload(1L);
        overload(1.0f);
        overload(1.0);
        overload(true);
    } 
    public static void main(String[] args) {

        JavaApplication1 o = new JavaApplication1();
        
        o.runOverloadMethods();
    }
}


/*
run:
 
char
byte
short
int
long
float
double
boolean

*/

 




answered Jul 3, 2017 by avibootz
edited Jul 3, 2017 by avibootz
...