Results 1 to 5 of 5
- 10-31-2012, 08:58 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Inheriting private stuff from a Superclass ... let's settle this once and for all!
I'm sure this has been asked a million time, but everywhere I look, people seem to over-complicate the answer ... so I'm STILL confused.
Do subclasses inherit the private fields of the superclass? That is, if the super class has a private variable called A, does the subclass get its OWN COPY of that variable called A, which is NOT the same variable, just has the same name?
Or, are private fields just not inherited AT ALL? If I want a private variable in my subclass just like in the superclass, I must explicitly define it in the subclass code?
- 10-31-2012, 09:02 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
Re: Inheriting private stuff from a Superclass ... let's settle this once and for all
The sub-class "is a" super-class, there is only one variable "A" per instance.
- 10-31-2012, 09:10 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
- 10-31-2012, 11:02 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 21
- Rep Power
- 0
Re: Inheriting private stuff from a Superclass ... let's settle this once and for all
This would make the super class useless.Or, are private fields just not inherited AT ALL? If I want a private variable in my subclass just like in the superclass, I must explicitly define it in the subclass code?
The sub class extends the super class, there is no "OWN COPY", there is only one instance.Do subclasses inherit the private fields of the superclass? That is, if the super class has a private variable called A, does the subclass get its OWN COPY of that variable called A, which is NOT the same variable, just has the same name?
Edit: or perhaps post some code to explain what confuses you.
-
Re: Inheriting private stuff from a Superclass ... let's settle this once and for all
Have a look at the accepted answer to this question: java - Does subclasses inherit private fields? - Stack Overflow
Similar Threads
-
Factory methods and inheriting from an abstract class
By bunburya in forum New To JavaReplies: 3Last Post: 11-22-2011, 05:51 AM -
Having trouble with inheriting constructor from superclass
By coasterguy10 in forum New To JavaReplies: 3Last Post: 10-20-2011, 05:07 AM -
Inheriting two kinds of Lists into one Class
By rsiddharth in forum New To JavaReplies: 22Last Post: 12-26-2010, 03:39 PM -
How is this dog inheriting a bark?
By fresh83 in forum New To JavaReplies: 3Last Post: 07-05-2010, 01:33 AM -
Ideas about private to private IP networking over the Internet
By mr_anderson in forum Advanced JavaReplies: 7Last Post: 06-28-2010, 07:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks