+ 6

What's the use of private ?

When we need private while making programmes?

1st Jul 2019, 5:09 AM
Foxie
Foxie - avatar
6 Réponses
+ 11
Private is an access specifiers which helps satisfy encapsulation and hence restrict the access of data members of a class to any function. When the data members are private they can only be accessed by the class itself. Hope it helps✌️
1st Jul 2019, 5:14 PM
Manoj
Manoj - avatar
+ 5
https://beginnersbook.com/2013/05/java-access-modifiers/ I think this is helpful. Bottom of this page contain a table ~that tells about the accessibility ☺
1st Jul 2019, 6:43 AM
Kelvin Paul
Kelvin Paul - avatar
+ 3
It prevents accidental modification of vital data.
2nd Jul 2019, 2:30 AM
Sonic
Sonic - avatar
+ 2
Private variables or methods can be accessed only from the methods of the class to which it belongs. A subclass also does not have access to the private variables.
2nd Jul 2019, 5:28 AM
Megha Pradhan
Megha Pradhan - avatar
+ 1
Private allows functions and variables of a class to only be used within that class. For security/dev team use. Protected allows only that class and its derived classes use them but they will not appear when just making the object type as a variable somewhere for use. And finally, public is used to give access everywhere. You can also use private, protected, and public when enheritting from another class and this determines how the public/protected variables and functions are brought in to the current class, even if their access keyword is more accessible
2nd Jul 2019, 3:26 PM
nk361
nk361 - avatar
+ 1
Private is an specifier which made us to satisfy encapsulation.if we make data members private then only class can access data members
4th Jul 2019, 10:47 AM
Vaibhav Mishra