Java代码不允许我将一个方法从一个类调用到另一个类
抱歉,这是一个很长的问题,但我无法使用pm将printPASSInfo()调用到另一个类。printPASSInfo()。pm是我试图调用的方法所在的类的名称。我可以把这个方法称为pm。打印信息很好,我不明白出了什么问题。很抱歉,这可能会让人困惑,而且很长,但请尝试帮助。谢谢大家!这是我的密码:
import java.util.Scanner;
public class Prog1Methods_FA11 {
String ssn, pw, phoneNumber,line;
Scanner input = new Scanner (System.in);
boolean validPW_Length = true,
validPW_Symbols = true,
validPW_enough_Digits = true;
boolean validSSN_Digits = true,
validSSN_Format = true,
validSSN_Length = true;
boolean validPhone_Symbols = true,
validPhone_Format = true,
validPhone_Length = true;
public Prog1Methods_FA11() {
}
// you may insert a method here to display password status
public void printPASSInfo(){
System.out.println("\t Password Information");
System.out.println("The Password:\t" + pw);
System.out.println("Password Lrngth:\t" + validPW_Length);
System.out.println("Password has minimum number of digits:\t" + validPW_enough_Digits);
System.out.println("Password has correct symbols:\t" + validPW_Symbols);
}
// you may insert a method here to display the phone number status
}
以下是我试图称之为:
case 2: System.out.println("Enter a password witha atleast 8 characters and atleast 2 numbers:\t");
pw = input.nextLine();
pm.readAndVerifyPASS(pw);
pm.printPASSInfo();
break;
还有滑稽的错误:
MySkeletonProgram1_FA11.java:53: cannot find symbol
symbol : method printPASSInfo()
location: class Prog1Methods_FA11
pm.printPASSInfo();
^
1 error
我声明pm对象:
public class MySkeletonProgram1_FA11{
public static void main(String[] args)throws Exception {
// Declarations
Scanner scan = new Scanner(System.in);
Scanner input = new Scanner (System.in);
Prog1Methods_FA11 pm = new Prog1Methods_FA11();
# 1 楼答案
对于您粘贴的类,这可以很好地编译和运行:
试试看,把你遇到的错误都贴出来