我想将员工内部班级Salarycal()
中的employeeInfo
方法称为班级Exc
public class Employee {
public class employeeInfo{
int id;
String name;
int Salary;
public employeeInfo(int id,String name,int Salary){
this.id=id;
this.name=name;
this.Salary=Salary;
System.out.println(id+name+Salary);
}
public int Salarycal(){
int totalSalary =0;
int b=getId();
........
}
}
import Employer.Employee.employeeInfo;
public class Exc {
public static void main(String[] args) {
//want to access the salarycal() method in this class
}
}
答案 0 :(得分:1)
这就是我通常会调用内部类
的方法Inner inner = new Outer().new Inner();
inner.methodToInvoke();
答案 1 :(得分:0)
喜欢@Ashish说:
public static void main(String[] args) {
new Employee().new employeeInfo().Salarycal();
}