Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the difference between the "protected and default"
modifiers?

Answer Posted / mythili s

It's all correct but one more must-be-notified and
interesting point i would like to add here along with these
is as follows.

When a protected class is extended by any other class, the
child class (in case it belongs to any other package) can
have the inheritance of the protected parent class. What if
any third class extends that child class of the protected
parent class?
Example:
PrClass1 is a protected class in package1.

Child1 is another class, belongs to package2.

..class Child1 extends PrClass1..

Here, Child1 is a class which gets all inheritance of
PrClass1.
Now, i have another class SubChilld1 belongs to package2
itself.

..class SubChild1 extends Child1..

What happens now? what happens to the PrClass1's members
which are now encapsulated by Child1???

Here we go...

Whenever the protected class is extended by any other
class, which is not in the same package, that class's
members will become private to that child class. So, even
if that child class is extended by any other class, the
private memebers of this child class cannot be accessed by.

This is a wonderful and nice point that has to be noticed.

Thanks.

Is This Answer Correct ?    23 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

why doesn't java run on all platforms?

1032


Suppose if we have variable ' I ' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared?

1058


Can we compare two strings in java?

1029


What is java Applet?

1110


How can you traverse a linked list in java?

1129


What is the most important feature of java? What is an interface?

1016


What are memory tables?

1096


What is difference between path and classpath variables?

1097


What are new features introduced with java 8 ?

996


Does every java program need a main?

1002


What is tcp ip in java?

1119


Differentiate storage classes on the basis of their scope?

1171


How an object is serialized in java?

991


What is java thread dump, how can we get java thread dump of a program?

1006


what is object slice?

2089