首页 > 代码库 > Java实验题3_8_林大锐格平台

Java实验题3_8_林大锐格平台

import java.util.Scanner;
class Employee {
    private String name;// 职员名称

    public Employee() {
	};

	public Employee(String s) {// 构造函数,初始化职员名称
		this.name = s;
	}

	public String GetName() { // 获取职员名称
		return name;
	}

}
class Manager extends Employee{
	String department;
	public Manager(String a,String b){
		super(a);
		
		department=b;
	}
	public String GetDepartment(){
		return department;
	}
}
//write your own codes

public class Main {
	public static void main(String[] args) {
	Scanner sca = new Scanner(System.in);
            String str = sca.next();
        	String str1 = sca.next();
            Manager m = new Manager(str, str1);
            System.out.println("name:"+m.GetName()+" department:"+m.department);
	}

}

  ****************************************************************************

子类在调用父类的构造函数时,需要使用super();来调用父类中隐藏的变量;

子类成员变量无法直接调用父类私有变量。

Java实验题3_8_林大锐格平台