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

What does the exclamation mark mean in java?

1171


Are arrays classes in java?

968


Explain exception chaining in java?

1089


What is hash code collision?

1006


What is boolean keyword in java?

1078


What is starvation?

1216


Is there a jre for java 11?

1010


why we use merge option in hybernate pls give a ex snippet

1931


What do you mean by flow of struts?

1227


What language is an assembler written in?

942


Are registers volatile?

886


Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)

1756


What is java util list?

881


Why do we need singleton?

929


What are java threads?

1066