• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

flow of program

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

can any one explain wht's the flow of program.


I think first staic block will executed first.after tht base class.is it right.


regards
Suhita
[ July 08, 2006: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First when t.method is called, since the method is static the type is resolved at compile time and so method of base class is called and prints 1.
In the next line the refernce "t" is cast to the sub class type and so the method of subclass is called and prints 0.
So the output is 1 0

Regards,
Chaitra
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What "staic block" are you referring to? I cannot see any static initializer in this program. Do you mean a static method?

Please, in future, use tags around your code to preserve its formatting.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calling a static method through a reference to an instance of a class is not the recommended way of doing it. It is clearer and more correct to call the methods as in T024.method() or Base.method().
 
reply
    Bookmark Topic Watch Topic
  • New Topic