Getting syntax error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Getting syntax error

Hi, I'm not able to find my error. I've handled all the brackets but still getting error. Please help. Syntax error on token "{", { expected after this token Syntax error, insert "}" to complete ClassBody https://code.sololearn.com/c1T07fMmHe36/?ref=app

10th Oct 2021, 12:57 PM
Ankush Raj
Ankush Raj - avatar
4 Answers
0
public class EncapsulationIntro{ public static void main(String[] args) { System.out.println("hello"); } public void doWork(){ System.out.println("do some work"); } } class LivingBeings{ String name; LivingBeings() { this.name = name; } }
10th Oct 2021, 1:53 PM
Atul [Inactive]
+ 2
Comment line 1: Package isn't supported in SoloLearn. Comment line 23 Invalid syntax, you write statements outside methods.
10th Oct 2021, 1:08 PM
Ipang
+ 2
Ankush Raj You can not write any statement without method or constructor. So you need to write this.name = name inside a method or constructor. Remember constructor is also a method but non returnable means you cannot have any return type.
10th Oct 2021, 3:17 PM
A͢J
A͢J - avatar
+ 1
Thanks 👍
10th Oct 2021, 1:22 PM
Ankush Raj
Ankush Raj - avatar