• 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

doubt in polymorphism

 
Greenhorn
Posts: 17
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

this is from Devaka's ExamLab:


Correct answer is "Sub1 2".
It's not clear for me why while evaluating ga.i, value is taken from Greek class?
Thanks.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Igor,

Polymorphism applies only to instance methods.

This question has been answered before. Check:

https://coderanch.com/t/427166/Programmer-Certification-SCJP/certification/from-Exam-lab-practice-Exam#1895372
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Igor Baiborodine wrote:Hi,

this is from Devaka's ExamLab:


Correct answer is "Sub1 2".
It's not clear for me why while evaluating ga.i, value is taken from Greek class?



The Arabic.getI() method overrides Greek.getI(), but the Arabic.i field does not override Greek.i. Overriding is a method-only thing.

Did that help?

We say that Arabic.i "shadows" Greek.i. From within the Greek class, Arabic.i is hidden by Greek.i, but that doesn't apply outside the Greek class.

 
Igor Baiborodine
Greenhorn
Posts: 17
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
Now it is clear.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic