되돌리기
ShapeTest 
class Shape {
    protected int x, y;
    public void draw() {
        System.out.println("Shape Draw");
    }
}
class Rectangle extends Shape {
    private int width, height;
    public void draw() {
        System.out.println("Rectangle Draw");
    }
}
class Triangle extends Shape {
    private int base, height;
    public void draw() {
        System.out.println("Triangle Draw");
    }
}
class Circle extends Shape {
    private int radius;
    public void draw() {
        System.out.println("Circle Draw");
    }
}
public class ShapeTest {
    public static void main(String[] args) {
        Shape s1, s2;
        s1 = new Shape();       // 당연하다
        s2 = new Rectangle();   // Rectangle 객체를 Shape 변수로 가르킬 수 있을까
    }
}예제 6-6
class Date {
    private int year, month, date;
    public Date(int year, int month, int date) {
        this.year = year;
        this.month = month;
        this.date = date;
    }
    @Override
    public String toString() {
        return "Date [year = " + year + ", month = " + month + ", date = " + date + "]";
    }
}
class Employee {
    private String name;
    private Date birthDate;
    public Employee(String name, Date birthDate) {
        this.name = name;
        this.birthDate = birthDate;
    }
    @Override
    public String toString() {
        return "Employee [name = " + name + ", birthDate = " + birthDate + "]";
    }
}
public class EmployeeTest {
    public static void main(String[] args) {
        Date birth = new Date(1990, 1, 1);
        Employee employee = new Employee("홍길동", birth);
        System.out.println(employee);
    }
}Share article