如何在Java

时间:2017-10-08 13:08:41

标签: java oop

class Department{

  int dep_id;
  string dep_name;

Department(string dep_id , string dep_name)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Department ID");
dep_id=input.nextInt();
system.out.println("Enter Department Name");
dep_name=input.nextString();
void Display(){
  System.out.println("Deaprtment ID is : " + dep_id);
  System.out.println("Deaprtment Name is : " + dep_name);

}

class Professor extends Person
{         //This person is different class

 string profName;
  Department dept;
 Professor(string profName){
  Scanner input=new Scanner(System.in);
  System.out.println("Enter Professor Name");
   profName=input.nextString();


 }

现在我必须补充一下  名为dept的数据字段,类型为Department 一个双参数构造函数,用于初始化用户定义值的两个属性 我怎样才能在Class Class教授中调用系类课程

提前感谢。 在这种情况下请帮助我。我不擅长Java,努力学习它。

1 个答案:

答案 0 :(得分:1)

希望这说清楚

    class Professor extends Person { // This person is different class

    string profName;
    Department dept;

    Professor(string profName, int dept_id, String dept_name) {
        this.profName = profName;
        dept = new Department(dept_id, dept_name);
    }
}

在主班使用扫描仪来获取这些输入