我有一些在类示例中是私有的方法,我想在测试类中使用它们来进行测试,如何访问这些方法并将它们保留为私有
import java.util.*;
public class Example
{
Scanner scanner;
public Example()
{
scanner = new Scanner(System.in);
}
private void enterName()
{
System.out.println("Enter name");
String name = scanner.nextLine();
System.out.println("Your name is: " + name);
}
private void enterAge()
{
System.out.println("Enter age");
int age = scanner.nextInt();
System.out.println("Your age is : " + age);
}
public void userInput()
{
enterAge();
enterName();
}
}
public class Test
{
public static void main(String args[])
{
Example n = new Example();
n.enterName();
n.enterAge();
}
}