class&object

时间:2024-06-10 20:03:20

类(class)是构造对象的模板或蓝图。

对象的行为是用可调用的方法定义的.

import java.time.*;

public class EmployeeTest{
public static void main(String[] args){ }
} class Employee{
// instance fields --------> object's state
private String name;
private double salary;
private LocalDate hireDay; // constructors -------> create object
public Employee(String name, double salary, int year, int month, int day){
this.name = name;
this.salary = salary;
hireDay = LocalDate.of(year, month, day);
} // methods ----> object's behavior
public String getName(){
return name;
} public double getSalary(){
return salary;
} public LocalDate getHireDay(){
return hireDay;
} }