jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q? From Valiveru's Site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q? From Valiveru Watch "Q? From Valiveru New topic
Author

Q? From Valiveru's Site

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I am trying to compile this program and was expecting a compilation error, but it did not give.
class BaseClass
{
public void aMethod()
{
System.out.println("I am a BaseClass method");
}
}
public class Cals extends BaseClass
{
public void aMethod()
{
System.out.println("I am a SubClass method");
super.aMethod();
}
public static void main(String [] arg)
{
Cals sc = new Cals();
sc.aMethod();
}
}
I was under the impression that the super.aMethod() is called after System.out.println() statement so it will give an error. Can anybody please explain why this is happening?
Thanks,
Subba Rao
Vlad G
Greenhorn

Joined: Dec 28, 2000
Posts: 17
I thought this restriction only applies to constructors.
VG.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Yeah, it is only with constructors that super or this have to be the first line of the body. For other methods, they can be anywhere.
Bill
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Yea! i do agree with you and Vlad.
Thanks!
 
Consider Paul's rocket mass heater.
 
subject: Q? From Valiveru's Site