• 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

inner class with superclass reference but with subclass object

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




in above program i have created an object of Prac255 and assigned it to the reference of Prac25(superclass of Prac255).

Que 1: how internally at mark 1 JVM is able to call method on Prac25's object which resides inside the
Prac255's object....??

in this case it is printing "Prac25 78"

Que 2: if we make the callMe() method default or public in Prac25 as well as Prac255 class...then
how callMe() of Prac255 gets called...?? why JVM didn't call callMe() of Prac25 in this case..??

in this case it is printing "Prac255"
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Prac25.this is a reference to the superclass. This isn't a common way of coding, but it does work

2) When expanding the access to non-private, polymorphism takes effect and Java uses the subclass version.
 
reply
    Bookmark Topic Watch Topic
  • New Topic