answersLogoWhite

0


Best Answer

A private member of a class can only be accessed by methods of that class.

A protected member of a class can only be accessed by methods of that class and by methods of a derived class of that class.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

No. The default access specifier on a class type object is private. On a non-class type structure, it is public.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is the default access specifier same as protected?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Explain the significance of public and protected and private access specifiers in inheritance?

These are all access modifiers in Java. a. Public - these are accessible anywhere. This is the least restrictive access specifier. b. Private - these are accessible only inside the declaring class. This is the most restrictive access specifier. c. Protected - these are in between public and private. These are accessible to all classes that inherit this class d. Package - this is the default access specifier. These are accessible to all classes that are present in the same package as the contained class.


Which is java default access specifier?

There is no such thing as an access specifier in Java. There are access modifiers.The default access modifier if unspecified is to allow access to classes in the current package only, except within an interface where the default is 'public'


What is meant by private access in c plus plus?

It isn't. Private is the default access for class members. For struct members, the default access is public. Aside from default access, a class and a struct serve the same purpose; to define a class. As such, the following class definitions are equivalent: class X { int a; }; struct Y { private: int b; }; Typically, we use a struct to define simple data types with trivial construction and use class for more complex data types, often to encapsulate an invariant or to acquire a resource, hiding the implementation details from consumers using private access.


If a data-item is declared as a protected access specifier then it can be accessed?

A class method or attribute (data item) that is declared protected can be accessed only by methods of the same class or by methods of derived classes of the class.


Define access specifiers in object oriented programming?

One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making them available only through its methods. In this way the chance of making accidental mistakes in changing values is minimized. Java allows you to control access to classes, methods, and fields via so-called access modifiers. The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible.Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes. A member has package or default accessibility when no accessibility modifier is specified.Access Modifiers1. Private2. Protected3. Default4. PublicPublic is the most liberal access modifier and Private is the most restrictive access modifier. NB there is no such thing as an 'access specifier' in Java, only access modifiers.

Related questions

Explain the significance of public and protected and private access specifiers in inheritance?

These are all access modifiers in Java. a. Public - these are accessible anywhere. This is the least restrictive access specifier. b. Private - these are accessible only inside the declaring class. This is the most restrictive access specifier. c. Protected - these are in between public and private. These are accessible to all classes that inherit this class d. Package - this is the default access specifier. These are accessible to all classes that are present in the same package as the contained class.


Which is java default access specifier?

There is no such thing as an access specifier in Java. There are access modifiers.The default access modifier if unspecified is to allow access to classes in the current package only, except within an interface where the default is 'public'


What is meant by default access of class in java?

That's what you get when you don't include any access specifier, such as "public" or "private". This default access gives access to any class in the same package.


What is meant by private access in c plus plus?

It isn't. Private is the default access for class members. For struct members, the default access is public. Aside from default access, a class and a struct serve the same purpose; to define a class. As such, the following class definitions are equivalent: class X { int a; }; struct Y { private: int b; }; Typically, we use a struct to define simple data types with trivial construction and use class for more complex data types, often to encapsulate an invariant or to acquire a resource, hiding the implementation details from consumers using private access.


How the jvm is able to access your class even you declare it using default access specifier but the same class is not accessed from other class which is declared in another package?

The JVM knows about all of your classes, no matter what package they are in or what access specifier you declared them with. The access specifier is only used to limit access from other classes.


If a data-item is declared as a protected access specifier then it can be accessed?

A class method or attribute (data item) that is declared protected can be accessed only by methods of the same class or by methods of derived classes of the class.


Define access specifiers in object oriented programming?

One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making them available only through its methods. In this way the chance of making accidental mistakes in changing values is minimized. Java allows you to control access to classes, methods, and fields via so-called access modifiers. The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible.Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes. A member has package or default accessibility when no accessibility modifier is specified.Access Modifiers1. Private2. Protected3. Default4. PublicPublic is the most liberal access modifier and Private is the most restrictive access modifier. NB there is no such thing as an 'access specifier' in Java, only access modifiers.


Define protected access modifire in c plus plus?

The access privileges in c++ are 1.public 2.private 3.protected and by default its private


What is the Diff between Access Specifiers and Access Modifiers?

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.


What is a C plus plus program to demonstrate the use of access specifiers?

Access specifiers apply to class and struct data types only. If a member is declared before an access specifier is declared, the default access is implied. Once an access specifier is declared, that specifier remains in force until another specifier is declared. Specifiers can be declared in any order and may be repeated as often as required. The following demonstrates usage and purpose of each specifier. class X { friend void f(); // Friends can be declared anywhere. private: // The default access specifier for class types (implied if omitted). int a; // Only accessible to members of X and to friends of X. protected: int b; // Same as private, also accessible to derivatives of X. public: int c; // Accessible to any code where X is visible. }; struct Y { friend void f(); // Friends can be declared anywhere. public: // The default access specifier for struct types (implied if omitted). int a; // Accessible to any code where Y is visible. protected: int b; // Same as private, also accessible to derivatives of Y. private: int c; // Only accessible to members of Y and friends of Y. }; struct Z : X {}; void f() { X x; x.a = 42; // OK! X::a is private and f is a friend of X. x.b = 42; // OK! X::b is protected and f is a friend of X. x.c = 42; // OK! X::c is public and X is visible to f. Y y; y.a = 42; // OK! Y::a is public and Y is visible to f. y.b = 42; // OK! Y::b is protected and f is a friend of Y. y.c = 42; // OK! Y::c is private and f is a friend of Y. Z z; z.a = 42; // OK! Z::Y::a is public and Z is visible to f. z.b = 42; // OK! Z::Y::b is protected and f is a friend of Y. z.c = 42; // OK! Z::Y::c is private and f is a friend of Y. } int main() { X x; x.a = 42; // error! X::a is private and main is not a friend of X. x.b = 42; // error! X::b is protected and main does not derive from X. x.c = 42; // OK! X::c is public and is X is visible to main. Y y; y.a = 42; // OK! Y::a is public and is Y is visible to main. y.b = 42; // error! Y::b is protected and main does not derive from Y. y.c = 42; // error! Y::c is private and main is not a friend of Y. Z z; z.a = 42; // OK! Z::Y::a is public and Z is visible to main. z.b = 42; // error! Z::Y::b is protected and main is not derived from Y. z.c = 42; // error! Z::Y::c is private and main is not a friend of Y. }


What is mean by accessibility?

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 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.