
class People{
//필드(Feild)
String name; //이름
int age; //나이
//메소드(Method)
public void printMyself(){
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
}
}
class Student extends People{
//필드(Field)
int korean_scroe; //국어성적
int math_score; //수학성적
int english_score; //영어성적
//생성자(Constrouct)
Student(String name, int age, int kor_score, int mat_score, int eng_score){
super.name = name; //부모 필드
super.age = age; //부모 필드
this.korean_scroe = kor_score;
this.math_score = mat_score;
this.english_score = eng_score;
}
//메소드(Method)
public void printScore() {
System.out.println("국어성적 : " + korean_scroe);
System.out.println("수학성적 : " + math_score);
System.out.println("영어성적 : " + english_score);
}
}
public class Main {
public static void main(String[] args) {
Student student = new Student("홍길동", 18, 100, 90, 80);
student.printMyself(); //부모 메소드 호출
student.printScore(); //자식 메소드 호출
}
}
추상 클래스는 인스턴스, 즉 객체를 만들 수 없다. 즉, new를 사용할 수 없다.
추상 메서드는 하위 클래스에게 메서드의 구현을 강제한다. (오버 라이딩이 강제된다.)
추상 메서드를 포함하는 클래스는 반드시 추상 클래스여야 한다.
순도100% 추상 메서드만 가지는 추상 클래스는 interface interface는 다중 구현이 가능