What will be the result of the following code execution?

class Alien {
  String invade(short ships) { return "a few"; }
  String invade(short... ships) { return "many"; }
public class Defender {
  public static void main(String [] args) {
    System.out.println(new Alien().invade(7));
Constant 7 has an int type by default. When the function is called an implicit narrowing conversion int → short is not performed, so the compilation error will occur.
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback