Computer Science, asked by Pragatinm, 10 months ago

There are two classes named class A and class B. Both classes are in the same package. Can a private member of class A can be accessed by an object of class B?​

Answers

Answered by mohammads
0

Answer:

yes

Explanation:

entire package has to be imported

Answered by ankhidassarma9
0

Answer:

There are two classes named class A and class B which are in the same package. A private member of class A can't be accessed by an object of class B as Private members of a class aren’t accessible outside the scope of that class and any other class even if it is in the same package can’t access them.​

Explanation:

  • Java's access specifiers are public, private, and protected.
  • Java also defines a default access level.
  • When a member of a class is private, then that can only be accessed by the  other members of that class. They are not allowed to be accessed directly by any other object or function outside the class. Only the member functions of that class  or the friend functions are allowed to access the private data members of the class.
  • When a member of a class is modified by the public specifier, then that member can be accessed by any other code even if it is outside the program.
  • By default , the member of a class is public within its own package, but cannot be accessed outside of its package.
  • Anything declared private cannot be seen outside of its class. When a member of a class does not have an explicit access specification, it is visible to subclasses as well as to other classes in the same package.
  • Even if we declared that element protected, it will be seen outside the current package but only to the classes that subclass our class directly.
Similar questions