• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

private methods

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can private methods be overloaded?
How about private final methods?They are not inherited and can they be overriden?
[ May 13, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Private methods are not visible outside the class.. so u can definitely overload and override it...

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

Originally posted by Shilpi M Ag:
[QB]Private methods are not visible outside the class.. so u can definitely overload and override it...
[QB]



Since private methods are not visible outside their class, you can't actually "override" the method as you would be doing if that superclass method was public. You're just providing a method with an identical method signature (access level, method name, parameter list) in a subclass.
From the subclass method's perspective, it wouldn't be "overriding" anything since it can't see the private superclass method in the first place.

I thought I'd make the clarification since the the word "override" has a special meaning in the context of object-oriented programming.

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

Originally posted by Shilpi M Ag:
[QB]Private methods are not visible outside the class.. so u can definitely overload and override it...
[QB]



Acutally, I don't think that technically counts as overriding

To quote the excellent K&B book (pg 75): "Since the subclass, as we've seen, cannot inherit a private method, it therefore cannot override the method - overriding depends on inheritance"
 
Kevin Scott
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shilpi M Ag:
[QB]Private methods are not visible outside the class.. so u can definitely overload and override it...
[QB]



Acutally, I don't think that technically counts as overriding

To quote the excellent K&B book (pg 75): "Since the subclass, as we've seen, cannot inherit a private method, it therefore cannot override the method - overriding depends on inheritance"
 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul!
Since it's not visible in the subclass, I can have the same name with same argument list and return type.Since I am not actually overriding, I don't need to follow the rules for access overriding(like access modifiers and exception). Am I rite?

Similarly I can have the method even thne superclass method is private and final.How abt the Polymorphic effects.In this case, Will it come in to role or not?Can anybody explain pl! Thanks
 
Shilpi M Ag
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry for having written the sentence in the wrong manner.. I meant to say that since it not visible the compiler will not complain.. since it is like a new method for the compiler
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the JLS, §8.4.6.3 Requirements in Overriding and Hiding:


Note that a private method cannot be hidden or overridden in the technical sense of those terms. This means that a subclass can declare a method with the same signature as a private method in one of its superclasses, and there is no requirement that the return type or throws clause of such a method bear any relationship to those of the private method in the superclass.

 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic