• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Polymorphism doesn't apply to static methods

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
You're calling crawl() not s.crawl(). Big difference

[edit: singly beaten to the punch!]
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Oh my, that is sneaky!

Just ran the code with s.crawl(); and noticed the difference.....
 
author
Posts: 8995
19
  • Mark post as helpful
  • send pies
  • 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: 10308
217
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I wouldn't call this sneaky.
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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
  • 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.



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!