0
use of private in place of public
If we use private in place of public wt happend
5 Respuestas
+ 3
private - No other class can access it.
public - every class can access it.
Example:
public class A {
private int x = 1; // this should be public
}
public class Program {
A a = new A();
a.x += 2; // Error because x is private
}
+ 19
private attributes of a class can only accessed fromm their own methods. But you have 3 types of classes public, protected and private. Maybe some links will help:
https://stackoverflow.com/questions/1020749/what-are-public-private-and-protected-in-object-oriented-programming
https://softwareengineering.stackexchange.com/questions/143736/why-do-we-need-private-variables
The most other sites I have found are very specific to the language...
+ 2
your methods are not easily accessed
+ 2
make all instance variables private. use getters to access them. don't set instance to public, you can access them that way but it is absolutely disgusting, like watching kittens being stabbed to death
+ 1
Tq