If I declare a variable to be private, am I able to re-declare it in another method?
This is key because I used Netbeans to generate my GUI code, and it uses the same names for variables every time. Is there any way that I can avoid having to change every variable?
ADDITION/EDIT: Does this also apply for the methods themselves? How about objects?
The local variables inside a method can not be declared with visibility modifiers (
public,private,protectedor default), only the attributes of a class can use those modifiers.You can reuse the same variable names across different methods, it won’t cause conflicts. It’s a good practice to name the local variables in a method with different names from those of the attributes of the class. To make myself clear: