• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Private Methods

 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, that private methods can be overloaded in the same class, but can they be overloaded in the derived class? Consider this code:



Can the abc method in B overload the abc() in A , which is not private?
 
Jorg Klein
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private methods don't get inherited.

Try to call the private method of class A in class B.
You can't call it.
[ February 15, 2006: Message edited by: Jorg Klein ]
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aum,

For future reference, when you have queries of this nature (and it is good to be inquisitive about things), you should type the code in, create the classes and try it out - learning by trying these little exercises yourself is an excellent way to learn (and probably come up with more questions).

Regards,
JD
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not positive, because im a beginner myself, but it would make more
sense to me to use protected, instead of private, since you want to
share the info. with child classes.

-monk
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John for your pragmatic advice. I understand that the best way to learn programming, or anything for that matter, is to practice it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic