[英]call a method of inner class from another class Java
I would like to call the Salarycal()
method from Employee inner class employeeInfo
to class Exc
我想从Employee内部类
employeeInfo
调用Salarycal()
方法到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
}
}
this is how I would usually invoke a method of inner class 这就是我通常调用内部类方法的方式
Inner inner = new Outer().new Inner();
inner.methodToInvoke();
Like @Ashish said: 就像@Ashish说的那样:
public static void main(String[] args) {
new Employee().new employeeInfo().Salarycal();
}
PS. PS。 Read about Code Conventions for the Java TM Programming Language
阅读有关Java TM编程语言的代码约定的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.