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

 
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
  • 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: 64629
225
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for both of the replies.

It's cleared things up like a treat.
 
Campbell Ritchie
Marshal
Posts: 64629
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!