• 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

seems like a private method is being inherited!

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


This prints : hello super.

How does that happen?
hello() is private and so is not available in Sub, right?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do keep in mind that the method is declared in Super and the private method is accessible from the Super class. So there is no problem. Try making a call to the private method from the Sub class itself and it will throw a compile time error
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the private method is not inherited or it is inherited but it is invisible?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the private method is a part of the Super class, it will be available to an instance of the sub-class. But as you said, it is hidden so you cannot access it. But you can't exactly say that it is inherited. You can try this by creating a private final method in the super class and trying to override it in the sub-class...
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The private method is just that, private to the Super class, so a subclass can't invoke it directly - it's hidden. But it's still there.

Since super is a keyword, using the word Super in the example is dangerous. It'd be alot easier to understand if the class was named parent or ancestor.

-Cameron McKenzie
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can you quote your sources and say where you got this question from.

 
Ranch Hand
Posts: 41
Mac OS X Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See i think it is quite simpler, private method hello() is not being inherited. it is called by the class Super itself with the public method hi(). So its leagal that a Class can call is private method. and other class is accessing it through public method hi() which is accessible for all. Rectify if i am wrong.

Thanks & Regards
Jeetendra...!!
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, you are right.
The same when we use setters to change private variables.
 
Aakash Goel
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mo Jay wrote:
Can you quote your sources and say where you got this question from.



Its not a question. You can find a similar piece of code at www.freejavaguide.com
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic