Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

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


7,788 questions

10,874 answers

573 users

How to overload method with diffrent data types in Java

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


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
...