• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method invocation

 
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
ExamLab Creator
Marshal
Pie
Posts: 4690
337
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic