+ 1
Getting error
class MyClass1 { System.out.println("Myclaass1"); } class MyClass2 { System.out.println("Myclass2"); MyClass1 mc = new MyClass1(); mc.MyClass1(); } class MyClass { public static void main(String[ ] args) { System.out.println("Hello World"); MyClass2 mc = new MyClass2(); mc.MyClass2(); } }
1 Resposta
+ 8
https://code.sololearn.com/cyrwnhMdDUu9/?ref=app
I guess, this is the working version of your code.
Actually, you can't call functions inside classes. You need to wrap them inside a function. Inside classes, you can define functions and inside those defined functions, you can call other functions. (Like System.out.println())
And next mistake is, you can't call a constructor. Constructor is call itself when you initialize a class.
After you initialize a class, you can call the functions inside it, using the variable you initialized class.
Hope, you got answer.