I am new to java. Can anyone please tell me best way to access private method variables in another class. Thank u
Asked
Active
Viewed 1,385 times
-1
-
1Their private for a reason, look for the getter method of the variable – Jay Harris Jul 18 '15 at 01:22
-
2Private methods are private for a reason, change the visibility of those methods (if you can) in order to access them. – almightyGOSU Jul 18 '15 at 01:24
1 Answers
2
Private variables are private for a reason- you're not supposed to be able to access them directly. Many classes do have getter methods though which allow you to access private variables but not change them. If you need to access private variables in your program, you need to rethink your design.

connorp
- 254
- 2
- 12