• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance doubt

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What You Can Do in a Subclass

A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in. If the subclass is in the same package as its parent, it also inherits the package-private members of the parent. You can use the inherited members as is, replace them, hide them, or supplement them with new members:


Now in same document there is another one given below.
Private Members in a Superclass

A subclass does not inherit the private members of its parent class.


http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

I am not getting how private member will be accessible through inheritance.
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't know which "document" you are reading from but private members are never inhered in any case.
Better to read from reliable resources . http://docs.oracle.com/javase/tutorial/
 
Paul Clapham
Sheriff
Pie
Posts: 20739
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:A subclass does not inherit the private members of its parent class.


In other words, the private members are not accessible through inheritance. (Statements about package-private members are irrelevant to that fact.)

I am not getting how private member will be accessible through inheritance.


 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
In other words, the private members are not accessible through inheritance.

Yes,but look first quote also.Can you explain about that ?
 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first one you quoted says package-private, in other words, the default visibility if you do not specify private, protected, or public.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:The first one you quoted says package-private, in other words, the default visibility if you do not specify private, protected, or public.

I am not getting your mean here.
 
Henry Wong
author
Marshal
Pie
Posts: 20885
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:
Junilu Lacar wrote:The first one you quoted says package-private, in other words, the default visibility if you do not specify private, protected, or public.

I am not getting your mean here.


There are four accessibility specifier types -- private, protected, public, and a fourth type. The fourth type is sometimes called the default type, sometimes called the package-private type, and to specify it, you need to not use the private, protected, or public keywords.

Henry
 
Winston Gutkowski
Bartender
Pie
Posts: 10100
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saloni jhanwar wrote:I am not getting your mean here.

The meaning is quite simple: 'private' and 'package-private' don't mean the same thing; as Henry just explained.

Winston

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic