• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Q? From Valiveru's Site

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought this restriction only applies to constructors.
VG.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea! i do agree with you and Vlad.
Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic