this在Java中使用关键字optional吗?或者我必须使用它吗?当它不是可选的?在下面的代码中,它不会影响我的应用程序,无论Employee我做了多少个实例.print即使细节不匹配,该方法也会打印员工详细信息而不会出现任何问题.
public class Employee {
String name;
int Salary;
int pension;
String workPlace;
String teleNo;
int age;
void printDetails(){
System.out.println("Name is : "+this.name );
System.out.println("age is : "+this.age );
System.out.println("WorkPlace is : "+this.workPlace );
System.out.println("Salary is : "+Salary );
System.out.println("Pension is : "+this.pension );
System.out.println("Telephone No. is : "+this.teleNo );
System.out.println("age is : "+Integer.toString(age) );
}
}
public class Main extends Employee {
/**
* @param args
*/
public static void main(String[] args) {
Employee …Run Code Online (Sandbox Code Playgroud)