2015年9月11日 星期五

Package & Import 用法

利用 Package 來將專案內的檔案,進行分類:
package com.HR;

public class Employee {

    private String name;
    private int empID;
    private String ssn;
    private double salary;

    public Employee() {
    }

    public Employee(int empID, double salary, String ssn, String name) {
        this.empID = empID;
        this.salary = salary;
        this.ssn = ssn;
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public String getSsn() {
        return ssn;
    }

    public String getName() {
        return name;
    }

    public int getEmpID() {
        return empID;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setEmpID(int empID) {
        this.empID = empID;
    }
}

Import 進來上述的 Class :
import com.HR.Employee;

public class Demo {
    public static void main(String[] args){
    
        Employee e1 = new Employee();
    
    }
}