1: class Class1
2: {
3: int total = 0;
4: public static void main( String[] args )
5: {
6: doIt();
7: }
8: void doIt()
9: {
10: for ( int i = 0; i < 5; i++ ) total += i;
11: System.out.println( total );
12: }
13: }
@282887833, actually you used class1 name. True! Added as additional option
2019 Apr 9, 7:42:26 PM
@282887833, thanks for your comment! But in this case we can not use "class" as variable name, as it is a reserved keyword. You will get next errors: Class1.java:6: error: not a statement Class1 class = new Class1(); class.doIt(); ^ Class1.java:6: error: ';' expected Class1 class = new Class1(); class.doIt(); ^ Class1.java:6: error: <identifier> expected Class1 class = new Class1(); class.doIt(); ^ Class1.java:6: error: illegal start of type Class1 class = new Class1(); class.doIt(); ^ Class1.java:6: error: <identifier> expected Class1 class = new Class1(); class.doIt(); ^ Class1.java:6: error: invalid method declaration; return type required Class1 class = new Class1(); class.doIt();
2019 Apr 9, 7:38:54 PM
This answer correct as well Class1 class1 = new Class1();class1.doIt();
2019 Apr 6, 10:19:04 AM
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать