+ 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.
2 Answers
+ 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...