0

What was the problem here.

The compiler says error on line 1 but if I run this same code on other online compiler it works perfect https://code.sololearn.com/cHlIHHZVUPP7/?ref=app

1st Jun 2023, 9:22 AM
GHOST
GHOST - avatar
4 Antworten
+ 5
You can move `enum Size` inside `Test` class, and modify its access level to public. Then inside Main.main() method, you can refer the enum by specifying the owning class - `Test` - as follows ... Test t1 = new Test(Test.Size.MEDIUM); t1.orderPizza();
1st Jun 2023, 10:40 AM
Ipang
+ 3
I'm not sure why this works, but if you move enum Size definition after the class Test definition, the error goes away... class Test{ ... } enum Size{ ... } class Main{ ... }
1st Jun 2023, 11:21 AM
Bob_Li
Bob_Li - avatar
+ 3
Bob_Li is right. Usually we would place each class in a separate file. In Sololearn we cannot do that and the mechanism that separates and compiles our single file, is a little wacky. So the order of the classes makes a difference.
1st Jun 2023, 1:55 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Thanks Ipang
1st Jun 2023, 10:43 AM
GHOST
GHOST - avatar