Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to overload method with diffrent data types in Java

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

Related questions

1 answer 141 views
1 answer 175 views
1 answer 128 views
1 answer 147 views
1 answer 267 views
1 answer 227 views
1 answer 207 views
...