aspose file tools*
The moose likes Beginning Java and the fly likes Inheritance doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance doubt" Watch "Inheritance doubt" New topic
Author

Inheritance doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

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.


Tell the difficulties that i am difficult.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Feb 09, 2012
Posts: 583

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

Joined: Feb 26, 2001
Posts: 4462
    
    6

The first one you quoted says package-private, in other words, the default visibility if you do not specify private, protected, or public.


Junilu - [How to Ask Questions] [How to Answer Questions]
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

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
Sheriff

Joined: Sep 28, 2004
Posts: 18847
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7816
    
  21

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance doubt