• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Please help with this question

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I have just come across this question:



The output is MarMol followed by dub...

but why dub?? I thought it would be uk?

Any help is greatly appreciated.

Kev
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Variables are set at complile time.Variables are accessed with the declared time ,which in this case is Helse.
 
Kevin Lam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still don't quite understand, any more explaination??

Thx
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin, The thing is..
Variables and Private methods are binded at the time of compilation.
So it looks for the type of reference u r using, but not for the
type of the object it holding.Got it?


 
Kevin Lam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I c... thx
 
Kevin Lam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if the reference variable called a private method in the above example, it will call the method of the declared type as well?
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This quesiton comes from my site and it includes the following explanation.

"The field displayed is that of the reference type HelSte and the method is from the class that has been instantiated with the call to new which is the version of the method in HarMol."

Is there some way I could clarify or expand this explanation?
Marcus
 
Kevin Lam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess your explaination only states as it as fact, but it didn't really explain why is it so....

Kev
 
Marcus Green
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried with a private method?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I try to understand it:

Since variables whether static or instance and static methods cannot be overridden, the compiler will not determine these members at runtime and the object denoted by the reference does not matter. They cannot be overridden so why would the compiler care about the object at runtime. So the compiler will just based the determination from the reference type.

Perhaps just remember this, always follow the reference type except on cases when a method is overridden, then follow the object type.

Hope that helps.

PS. Try making jume() static, then it is not overridden but hidden. See if the results will change.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic