| 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
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
|
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 (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- 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
|
 |
 |
|
|
subject: method invocation
|
|
|