• 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 65814
250
  • 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: 23840
141
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: 65814
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!