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

method invocation  RSS feed

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two classes Test1 and Test2:

public class Test1 {

public void doFooStuff() { }

}

public class Test2 extends Test1
{
public void doTest2Stuff() {


}

Test2 t2 = new Test2();
t2.doTest2Stuff(); // syntax error..




public static void main(String args[])
{
System.out.println("inside the main methjod");

}
}

Can someone please let me know why it errors. If i mention Test2 t2 = new Test2();
t2.doTest2Stuff(); inside main() or inside doTest2Stuff() it doesnt error.

Thanks..
 
Devaka Cooray
Marshal
Posts: 5562
709
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting an error on that statement because it doesn't belong to a scope. Statements should reside in a scope - inside a method, constructor, or an initialization block. Please UseCodeTags when you post a code. It's unnecessarily hard to read the code otherwise.
 
pankaj vijay
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jose a method execution starts from main method not from else where.

you are writing code that can not be reached from anywhere that's why its is showing error
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!