• 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

Polymorphism doesn't apply to static methods

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code from Sun Web Learning Center




Output is

shuffling shuffling


because Polymorphism doesn't apply to static methods

But in the for loop on line 7, the first iteration is



Isn't the reference variable of type Slug? They why isn't it printing

crawling

Similarly, in the second iteration




Isn't the reference variable of type Slug? They why isn't it printing

crawling
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your output is shuffling shuffling is because you are calling static void crawl() { System.out.print("shuffling "); } from Line 8.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're calling crawl() not s.crawl(). Big difference

[edit: singly beaten to the punch!]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sandra Bachan wrote:

Isn't the reference variable of type Slug?



Yes. But is the application using the reference variable to call the method?


[EDIT: wow, that was fast -- doubly beaten to the answer]

Henry
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my, that is sneaky!

Just ran the code with s.crawl(); and noticed the difference.....
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a question for the crowd...

Sandra, I promise I'm not singling you out - we often hear that the exam is tricky or sneaky.

So, is this question sneaky, or is it an example of a bug you might have to track down on the job?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't often encountered this problem (because I tend not to shadow method names), but I think it's well worth exploring. I think Sandra learned a valuable lesson.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't call this sneaky.
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bert Bates wrote:I've got a question for the crowd...

Sandra, I promise I'm not singling you out - we often hear that the exam is tricky or sneaky.

So, is this question sneaky, or is it an example of a bug you might have to track down on the job?




How interesting. Didn't realize it could be a coding error
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I haven't often encountered this problem (because I tend not to shadow method names), but I think it's well worth exploring. I think Sandra learned a valuable lesson.



 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic