Вот код (прикрепленное изображение). и Варианты ответов: 0 5 ошибка компиляции counter = 5
я набрал его в IDEA и он вызывает: Error:(4, 26) java: Illegal static declaration in inner class com.company.Main.ItemCounterHolder modifier 'static' is only allowed in constant variable declarations Error:(14, 36) java: non-static variable this cannot be referenced from a static context Error:(15, 28) java: cannot find symbol symbol: variable counter location: class com.company.Main
Это и будет ответ ошибка компиляции или я что-то не учёл? Вот набранный код из IDEA с количеством строк соответствующим выданной ошибке: 1 package com.company; 2 public class Main { 3 public class ItemCounterHolder { 4 private static int counter = 0; 5 void ItemCounterHolder() { 6 7 counter = 5; 8 } 9 ItemCounterHolder(int x) { 10 counter = x; 11 } 12 } 13 public static void main(String[] args) { 14 ItemCounterHolder holder = new ItemCounterHolder(); 15 System.out.println(counter); 16 } 17 }
0
5
ошибка компиляции
counter = 5
я набрал его в IDEA и он вызывает:
Error:(4, 26) java: Illegal static declaration in inner class com.company.Main.ItemCounterHolder
modifier 'static' is only allowed in constant variable declarations
Error:(14, 36) java: non-static variable this cannot be referenced from a static context
Error:(15, 28) java: cannot find symbol
symbol: variable counter
location: class com.company.Main
Это и будет ответ ошибка компиляции или я что-то не учёл?
Вот набранный код из IDEA с количеством строк соответствующим выданной ошибке:
1 package com.company;
2 public class Main {
3 public class ItemCounterHolder {
4 private static int counter = 0;
5 void ItemCounterHolder() {
6
7 counter = 5;
8 }
9 ItemCounterHolder(int x) {
10 counter = x;
11 }
12 }
13 public static void main(String[] args) {
14 ItemCounterHolder holder = new ItemCounterHolder();
15 System.out.println(counter);
16 }
17 }