answersLogoWhite

0


Best Answer

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:

1. Public

2. Protected

3. Default and

4. Private

Java does not have a friendly access modifier.

Public Members:

If a variable or method is declared public, it means that it can be accessed by anyone or any other class (irrespective of which package they are in).

Private Members:

Members marked private can't be accessed by code in any class other than the class in which the private member was declared

Protected and Default Members:

The protected and default access control levels are almost identical, but with one critical difference. A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What do you mean by public private protected and friendly?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What do you mean by protected derivation of a sub class from base class?

When you derive a class (the sub-class) from a base class using protected access, all public members of the base class become protected members of the derived class, while protected members of the base class will remain protected. Private members are never inherited so they remain private to the base class. By contrast, if you use public inheritance, the public members of the base class remain public to the derived class, while protected members of the base class remain protected in the derived class. If you use private inheritance, both the public and protected members of the base class become private to the derived class. Note that accessibility cannot be increased, only reduced or left the same. That is, a protected member of a base class cannot be inherited as a public member of a derived class -- it can only be declared private or remain protected. Note also that accessibility is viewed from outside of the derived class. That is, all members of a base class other than the private members are inherited by the derived class and are therefore fully accessible to the derived class. But from outside of the derived class, all base class accessibility is determined by the access specified by the type of inheritance.


What is the difference between protected and friend in c plus plus?

The private, protected and public keywords are used to modify the access specifiers of class or struct members. Unless otherwise specified, class members are private by default, while struct members are public by default. Private members of a class are only accessible to members and to friends of that class. Protected members are the same as private members, but are also accessible to derived classes. Public members have unrestricted access. The private, protected and public access specifiers can also be used to modify the type of inheritance that applies to a derived class. Private inheritance means all public and protected members of the base class become private members of the derived class. Protected inheritance means all public members of the base class become protected members of the derived class. Public inheritance means all public and protected members of the base class remain public and protected members of the derived class. Private members of the base class are never inherited by derived classes. A derived class or one or more of its member functions may be declared a friend of the base class, thus permitting private access, but you would never do this unless the hierarchy were a closed, static hierarchy where all derivatives can be determined at compile time. Dynamically bound derivatives of unknown origin cannot be declared friends.


What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


What is public access specifier?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are: 1. Public 2. Protected 3. Default and 4. Private Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object. Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.


How can the base class data be accessed from database directly using derived class?

In order to access a base class member the base class member must be declared protected or public. Private data is only accessible to members of the same class and to friends of the class. I'm not entirely sure what you mean by accessing from a database. A derived class does not require a database in order to access its base class members, it only requires protected access at the very least. Note that although you can declare derived classes to be friends of their base classes and thus allow private access, it would be an unusual design since base classes should never know anything about any of their derivatives.

Related questions

What do you mean by protected derivation of a sub class from base class?

When you derive a class (the sub-class) from a base class using protected access, all public members of the base class become protected members of the derived class, while protected members of the base class will remain protected. Private members are never inherited so they remain private to the base class. By contrast, if you use public inheritance, the public members of the base class remain public to the derived class, while protected members of the base class remain protected in the derived class. If you use private inheritance, both the public and protected members of the base class become private to the derived class. Note that accessibility cannot be increased, only reduced or left the same. That is, a protected member of a base class cannot be inherited as a public member of a derived class -- it can only be declared private or remain protected. Note also that accessibility is viewed from outside of the derived class. That is, all members of a base class other than the private members are inherited by the derived class and are therefore fully accessible to the derived class. But from outside of the derived class, all base class accessibility is determined by the access specified by the type of inheritance.


Difference bitween various visibility modes used c plus plus?

By visibility I assume you mean member accessibility. C++ uses three levels of accessibility: private, protected and public. Private members are only accessible to the class itself and friends of the class. Protected members are the same as private members except derived classes also have access. Public members are fully accessible. With regards inheritance, base class members with greater access than that specified are reduced to the specified access in the derived class. Thus public inheritance has no effect on base class member access. Protected inheritance reduces public members of the base class to protected members of the derived class. Private inheritance reduces both public and protected members of the base class to private members of the derived class. Private members of the base class are never inherited, thus they always remain private to the base class. Note that access to base class members can never be increased through inheritance, only reduced or kept the same. However, as well as defining an overall inheritance access, you can also specify member-wise inheritance access. Thus you could use public inheritance overall, but specify certain public members of the base class to be protected or private in the derived class and/or certain protected members of the base class to be private members of the derived class.


What does private worship mean?

Worship that is not in public.


What does private domain mean?

Hi,Private domain means registering a domain by keeping your personal information hidden from the public by Whois privacy.I got this service by registering a domain in the site Whoisxy.com


What does being private in public mean?

leaving people alone


What do you mean by movie private screening?

A private screening of a film is not open to the general public. You are usually invited to private screening.


What does public management mean?

Public management means the use of private-sector management tools by the government. Various private and public domain tools are used to maximize on effectiveness and efficiency.


What words mean the opposite of private?

exposed, open, public, unrestricted,


What rare the main differences between public and private sector?

I take it you mean what are instead of what rare. The private sector is owned by the people. The public sector is owned by the government.


What do you mean by dont wash your dirty linen in public?

It is a proverb which means do not talk about your private family problems in public.


Is UCSC private?

It is not a private college because it is a University of California, which mean it's public. Private schools are USC, Stanford, Harvard and much more


What is the difference between protected and friend in c plus plus?

The private, protected and public keywords are used to modify the access specifiers of class or struct members. Unless otherwise specified, class members are private by default, while struct members are public by default. Private members of a class are only accessible to members and to friends of that class. Protected members are the same as private members, but are also accessible to derived classes. Public members have unrestricted access. The private, protected and public access specifiers can also be used to modify the type of inheritance that applies to a derived class. Private inheritance means all public and protected members of the base class become private members of the derived class. Protected inheritance means all public members of the base class become protected members of the derived class. Public inheritance means all public and protected members of the base class remain public and protected members of the derived class. Private members of the base class are never inherited by derived classes. A derived class or one or more of its member functions may be declared a friend of the base class, thus permitting private access, but you would never do this unless the hierarchy were a closed, static hierarchy where all derivatives can be determined at compile time. Dynamically bound derivatives of unknown origin cannot be declared friends.