For example,
public class Folder {
// ...
private List<Subfolder> subfolders;
}
and
public class Subfolder extends Folder {
// ...
}
If I'm understanding correctly, a Subfolder
will inherit all the fields of the Folder
superclass, including its List<Subfolder>
. However, because the list is private to Folder
, and as long as I don't write any accessor or mutator methods for the list, I can rest assured that a Subfolder
will not be able to do anything with Folder
's list of subfolders. What I feel conflicted about is whether this is considered good design. If a Subfolder
is unable to access the Folder
's list of subfolders, why inherit it at all?