JAVA

JAVA- 객체 지향 언어임을 보여주는 문제 예제

record2080 2025. 1. 11. 23:41

package practice;

 

class Book { //class book의 매개변수는 2개
             String title;
             String writer;
             

              Book(String title){   //제목은 외부에서 받고, 작가는 작자미상일수도 있고
                        this.title=title;
                        this.writer="작자미상";
    }
             Book(String title,String writer){ 작가는 외부에서 받는 경우도 있다.
                        this.title=title;
                        this.writer=writer;
   }
            void printBookInfo() {
                                   System.out.println(this.title+" "+this.writer);
}
}

public class Test02 {
                      public static void main(String[] args) {

                             Book book01=new Book("해리포터","JK롤링"); //멤버변수가 2개
                             Book book02=new Book("춘향전"); //멤버변수1개

                             book01.printBookInfo();
                             book02.printBookInfo();

}
}

'JAVA' 카테고리의 다른 글

저는 이제 노션으로 떠납니다 안녕  (0) 2025.04.11
7일차 강의- 함수 유형  (0) 2025.01.19
자바- 객체 지향 언어의 특징  (0) 2025.01.10
버블배열 (BUBBLE)  (0) 2025.01.04
배열문제 ①  (0) 2025.01.02