Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Why is the output of the following code...?

public class Yikes {

public static void go(Long n) {System.out.println("Long ");}

public static void go(Short n) {System.out.println("Short ");}

public static void go(int n) {System.out.println("int ");}

public static void main(String [] args) {

short y = 6;

long z = 7;

go(y);

go(z);

}

}

the output of the above code is int long but why and how?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    No, because it's Java and the S on Short is capitalized.

    Try this code out with your variable types in lowercase.

    public class Yikes {

    public static void go(long n) {System.out.println("Long ");}

    public static void go(short n) {System.out.println("Short ");}

    public static void go(int n) {System.out.println("int ");}

    public static void main(String [] args) {

    short y = 6;

    long z = 7;

    go(y);

    go(z);

    }

    }

  • 1 decade ago

    Because the values 6 or 7 can be long or short. It is running the first GO that it finds and it reports that the number is long.

    Source(s): VB.NET Programmer
Still have questions? Get your answers by asking now.