• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

private & Static

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know if I understood the concept correctly.I would appreciate answers for the following questions.
1)private memeber are not visible in subclass .so if we define any method same as super class method then it is a new method in sub class .so it is not overriding.
Are private methods inherited?
2)static methods are hidden in subclass.any sub class method same as super method will be a new method in sub class.so it is not overriding.
Are static methods inherited?
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony!
You may want to check this out ...
http://www.javaranch.com/maha/Discussions/Language_Fundamentals/difference_between_static_and_final_method_-_JavaRanch_Big_Moose_Saloon.htm
Brian
 
Tony reedy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi brian,
I did go thru many questions in this site.After all this ,I got the above concepts.Correct me if i am wrong.Did I mess up some things.
--also I would appreciate answers for the above questions.
Thanks
Tony
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The best way to answer your questions would be to write some code and see what happens.
Good Luck,
-Dirk Schreckmann
 
Tony reedy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did do some sample programs.I know what will be the out put .what i want to know is ..what will be the answers if a question like
are private members inherited?
are static members inherited?
-thanx
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)private memeber are not visible in subclass. so if we define any method same as super class method then it is a new method in sub class. so it is not overriding.

true.

Are private methods inherited?

no.

2)static methods are hidden in subclass. any sub class method same as super method will be a new method in sub class. so it is not overriding.

true.

Are static methods inherited?

Yes, as long as they are not hidden by a new method of the same signature in the sub class and they are not private.
[ March 08, 2002: Message edited by: Marilyn deQueiroz ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally Tony got the answers he was looking for.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the contrary...
Writing some code helps to give us a fuller picture of what's going on.
Marilyn, I'm not explicitly disagreeing with your explanation on inheriting static methods. I contend that static methods are not inherited in every polymorphic sense of inheritance.
Consider:



Good Luck,
-Dirk Schreckmann
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic