answersLogoWhite

0


Best Answer

No.

In Java, the private access modifier restricts member access to the class in which the member is declared. But in C++, private members are also accessible to friends of the class in which they are declared. The rough equivalent in Java would be package private access.

Not that Java doesn't have access specifiers, it has access modifiers. When no modifier is specified, default access is implied, which is package private for classes and public for interfaces.

User Avatar

Wiki User

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

Wiki User

10y ago

Java has the same access specifiers as C++ which work in the same way. The only difference is the way in which default access works. In C++, default access is private for class structures and public for struct structures. In Java, default access lies between protected and private, allowing access from the class itself as well as from other classes within the same package, however subclasses have no access unless contained in the same package.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Are the private access specifiers in Java and C plus plus the same?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the default access specifier in C plus plus?

private


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


Does Visual Java plus plus and Java Builder is different from the Java language?

Yes!Visual Java plus plus and Java Builder is different from the Java language?


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 computer language java or C plus plus should you use to design an app for the ipod or should i use a software?

You would use neither Java nor C++, you would use Objective-C, in conjunction with the Apple iPod API (iPod Library Access).

Related questions

What are the access control specifiers used in c plus plus?

The access control specifiers in C++ are...public - to denote that the member is accessible from any in scope codeprivate - to denote that the member is accessible only from within the containing classprotected - the same as private, except that derived classes are includedPrivate is the default for a class type object, while public is the default for a structure type object.


What is the default access specifier in C plus plus?

private


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


Does Visual Java plus plus and Java Builder is different from the Java language?

Yes!Visual Java plus plus and Java Builder is different from the Java language?


Which is more popular c plus plus or java?

Java


Which is easier 'C plus plus' or 'Java'?

Java is considerably easier than C++.


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 computer language java or C plus plus should you use to design an app for the ipod or should i use a software?

You would use neither Java nor C++, you would use Objective-C, in conjunction with the Apple iPod API (iPod Library Access).


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


How java use extern key word which is used in C plus plus?

No extern keyword in Java.


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.


What language is completely object oriented c plus plus or java?

Java is the complete object oriented Programming Language as every thing in java is an object,