• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

method invocation

 
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..
 
Sheriff
Posts: 6676
1267
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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.
 
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
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic