Java class does it work like this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java class does it work like this?

class MyClass { /*static void x creates a varible that can be called from main which can be used to create diffrent strings*/ static void x (String y) { System.out.println("My favorite games are " + y); } /*main*/ public static void main(String[ ] args) { /*calls x*/x(/*string y =*/"Zelda"); /*calls x*/x(/*string y =*/"Mario"); /*calls x*/x(/*string y =*/"Sonic"); /*calls x*/x(/*string y =*/"Tekken"); /*Each once executes with System.out.println*/

14th Jul 2017, 6:51 PM
D_Stark
D_Stark - avatar
2 Answers
+ 4
Other than missing the closing braces for the main method and My class this code works fine. x() however is not a variable as you're describing it in your comment, it is a method.
14th Jul 2017, 7:07 PM
ChaoticDawg
ChaoticDawg - avatar
0
I just tried it in code playground: ..\Playground\\.java:17: error: reached end of file while parsing x("Tekken");
14th Jul 2017, 6:53 PM
Dillion Piazza
Dillion  Piazza - avatar