Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Explain the error after compilation of the given code  RSS feed

 
Sanjeet Rana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags to your post, and you can see how much better it looks. Please always use them. Also avoid tabs for indenting; use spaces instead.
What was the error? You should always tell us.
Now I have indented the code, you can see there is a statement outside a method. I think you wanted a } two lines later than you actually wrote.
 
Sanjeet Rana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time error is :
Subclass.java:15: error: <identifier> expected
obj.method1();
^
1 error

So give explanation for this error.
 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put code outside a method (or constructor or initializer), that code can only consist of declarations. And those declarations would be declaring either instance variables or class variables, depending on whether you used the "static" modifier. Any other code (i.e. any code which isn't a declaration) has to go inside a method (or constructor or initializer).
 
Sanjeet Rana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I got the concept.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!