+ 2

How to call multiple methods which is in same class to main class?

I've two methods which is in one class, and one another class which is the main class. whenever I try to call the two methods in main class, the compiler shows error.

30th Apr 2018, 5:41 PM
Vishnu Murali
2 odpowiedzi
+ 4
The issue is that the variable 'salary' is only defined in the method getDetails(). It cannot be accessed from printDetails(). One way to fix this is to increase the scope of the variable. Like so: class printing { int salary; public void getDetails() { Scanner sc = new Scanner (System.in); System.out.println ("enter salary"); salary = sc.nextInt(); } etc...
30th Apr 2018, 6:33 PM
Rrestoring faith
Rrestoring faith - avatar
30th Apr 2018, 6:26 PM
Vishnu Murali