从另一个类Java调用内部类的方法

时间:2014-01-08 20:16:47

标签: java

我想将员工内部班级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
        }

}

2 个答案:

答案 0 :(得分:1)

这就是我通常会调用内部类

的方法
Inner inner = new Outer().new Inner();
inner.methodToInvoke();

答案 1 :(得分:0)

喜欢@Ashish说:

public static void main(String[] args) {
    new Employee().new employeeInfo().Salarycal();
}

PS。阅读Code Conventions for the Java TM Programming Language

相关问题