“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
Public: Makes class memebrs accessible outside the class. It can be accessed in the C code. Private: Makes the members specified accessible only to the class and it’s functions.
public - Anyone can access the method/variable protected - The method/variable can only be accessed by classes which inherit from the class in which the method/variable is declared. private - The method/variable can only be accessed from within the class where it is declared.
Public: can be accessed from other type of access specifiers, namely a Private class, a protected class or anyother public class.
This may be extended to C++ and Java
Private: has restricted access to its member functions declared in this type modifier. Only the members with-in may access them. But there’s a loop hole, what if a variable is declared in Public section of a Private class modifier?
public: the variables and class members that are declared as public can be accessed any where in the program.
private: the members function can accessed only by that pertical class and inside the class
Public: If a variable or methode is declared as public it can be access any where in the program.
private: if a variable or methode is declared as private it can be access with in the class where declared or member function can only access that class variable.
public members can be accesed outside the class where as private can only be accesed by class methods.private cannot be accesed outside the class.
only with the help of friend functions and friend classes it can be accesed outside the class
Public:
Makes class memebrs accessible outside the class. It can be accessed in the C code.
Private:
Makes the members specified accessible only to the class and it’s functions.
public - Anyone can access the method/variable
protected - The method/variable can only be accessed by classes which inherit from the class in which the method/variable is declared.
private - The method/variable can only be accessed from within the class where it is declared.
public / private have two different meanings in C++.
1. To specify the access privilege of the class members.
2. To specify what type of inheritance.
Public: can be accessed from other type of access specifiers, namely a Private class, a protected class or anyother public class.
This may be extended to C++ and Java
Private: has restricted access to its member functions declared in this type modifier. Only the members with-in may access them. But there’s a loop hole, what if a variable is declared in Public section of a Private class modifier?
public: the variables and class members that are declared as public can be accessed any where in the program.
private: the members function can accessed only by that pertical class and inside the class
Public: The field/Method is accessible out side the class also.
Private: Fields/Methods restricted and are available inside the class only.
Public: If a variable or methode is declared as public it can be access any where in the program.
private: if a variable or methode is declared as private it can be access with in the class where declared or member function can only access that class variable.
Hey! Don’t forget that ‘friend’s can access private and protected members.
public members can be accesed outside the class where as private can only be accesed by class methods.private cannot be accesed outside the class.
only with the help of friend functions and friend classes it can be accesed outside the class
Leave an Answer/Comment