This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes method invocation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method invocation" Watch "method invocation" New topic
Author

method invocation

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3112
    
  42

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
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


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
 
GeeCON Prague 2014
 
subject: method invocation