GunterOdimm / Java_Study

0 stars 0 forks source link

Java Test Study Code 016 - 상속 개념 #21

Open GunterOdimm opened 5 years ago

GunterOdimm commented 5 years ago

최상단 부모 클래스


public class Article {

    private int num;
    private String title;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}
GunterOdimm commented 5 years ago

자식클래스 QNAArticle


public class QNAArticle extends Article {

    private String answer;

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Override
    public String toString() {
        return "질문/답변 [글번호=" + getNum() + ",제목 =" + getTitle() + ",답변 =" + answer + "]";
    }

}

자식 클래스 FileArticle


public class FileArticle extends Article {

    private String FileName;

    public String getFileName() {
        return FileName;
    }

    public void setFileName(String fileName) {
        FileName = fileName;
    }

    @Override
    public String toString() {
        return "자료실 [번호 =" + getNum() + ",제목 = " + getTitle() + ", 첨부파일 =" + FileName + "]";
    }

}
GunterOdimm commented 5 years ago

메인 LibrarySearch 클래스


public class LibrarySearch {
    public static void main(String[] args) {
        FileArticle FileArticle1 = new FileArticle();
        FileArticle1.setNum(1);
        FileArticle1.setTitle("첫번째 자료입니다");
        FileArticle1.setFileName("자바.ppt");
        System.out.println(FileArticle1.toString());

        System.out.println("----------------------------------");

        QNAArticle QNA = new QNAArticle();
        QNA.setNum(1);
        QNA.setTitle("첫 번째 질문입니다");
        QNA.setAnswer("첫 번째 답변입니다");
        System.out.println(QNA.toString());
    }

}