I am learning Java and currently just try to use OOP in everything. I have created a Class which has two methods one returns String and another an Int. Both methods have scanners so the output is whatever user types in. In addition I have another method where I have main method and method where previous two are executed. Whenever I try to call both methods the program crashes, however it works normally if I call only one of them. Any ideas will be helpful to me.
package uno;
import dos.SupportClass;
public class MainClass {
public static void main(String[] args) {
MainClass mainObj = new MainClass();
mainObj.checkFunctino();
}
public void checkFunctino() {
SupportClass obj = new SupportClass();
System.out.println("test");
String check = obj.returnString();
System.out.println(check);
int temp = obj.returnInteger();
System.out.println(temp);
}
}
package dos;
import java.util.Scanner;
public class SupportClass {
public String returnString() {
Scanner scan = new Scanner(System.in);
String response = scan.nextLine();
scan.close();
return response;
}
public int returnInteger() {
Scanner scan = new Scanner(System.in);
int response = scan.nextInt();
scan.close();
return response;
}
}