Getting error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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(); } }

26th Jun 2019, 11:06 PM
KASARLA MAHESH
1 Answer
+ 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.
27th Jun 2019, 3:21 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar