• 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 & Static Methods Question

 
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm new to the forum, I have heard loads of great stuff about the site so I thought I would join!
Im studying for the OCA Java SE8 exam (I hope I am in the right place).

I was browsing the Oracle Java sample questions and came across a question that got me stumped, its below.
Now when I see overridden methods (I understand this is hidden because its static) I first look at the class that the reference is pointing too, in this case its programmer, so I presumed the answer would be"Writing Code", however its A, "Writing...", can anyone shed some light into why this is?

Thanks very much in advance.


What is the result?
A) Writing...
B) Writing book
C) Writing code
D) Compilation fails.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Ains Clark wrote:Hi there,

I'm new to the forum, I have heard loads of great stuff about the site so I thought I would join!

I hope you heard we are good. If so, they are right.

. . . overridden methods (I understand this is hidden because its static)

Don't mix terminology; those methods are hidden, not overridden.

I first look at the class that the reference is pointing too, in this case its programmer,  . . . .

No, the reference is declared as Writer. In the case of static methods, look at the type on the left (=declared type); for instance methods which are overridden and polymorphic, it is the type on the right (=runtime type) that counts.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ains Clark (in topic title) wrote: Polymorphism & Static Methods Question



... Or in other words. Static methods can't be overridden, and hence, does *not* support polymorphism.

and BTW, welcome to the ranch....

Henry
 
Ains Clark
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for both of the replies.

It's cleared things up like a treat.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a pleasure
 
reply
    Bookmark Topic Watch Topic
  • New Topic