Дан код:

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));
  }
}
Какой будет результат?
Explanation
Константа 7 по умолчанию имеет тип int. При вызове функции неявное сужающее преобразование int → short не выполняется, поэтому происходит ошибка компиляции.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes