Java - 추상 클래스 만들기 추상화
비슷한 내용을 만들 때 매번 새로 만들어야 할까 아니면 틀을 가져다쓰는게좋을까 당연히 후자일것이다.
-> is a 상속을 하면된다.
- 뼈대로 만들기 1
- Exam 이 뼈대로만 사용할 수 있도록 만든다. 즉 객체화 되는것을 막는다.
public abstract class Exam {
int kor;
int eng;
int math;
public Exam() {
this(0,0,0);
}
public Exam(int kor, int eng, int math) {
this.kor=kor;
this.eng=eng;
this.math=math;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int total() {
return kor+eng+math;
}
public float avg() {
return total()/3.0f;
}
댓글남기기