java oop : class, object, instance

This commit is contained in:
haerong22
2021-03-07 16:00:47 +09:00
parent 61893a9dcb
commit 765691e6fa
2 changed files with 43 additions and 0 deletions

25
JavaOOP/src/Java13.java Normal file
View File

@@ -0,0 +1,25 @@
import object.BookDTO;
public class Java13 {
public static void main(String[] args) {
// 책 -> class(BookDTO) -> 객체 -> 인스턴스
String title = "자바";
int price = 25000;
String company = "출판사";
int page = 890;
// 데이터 이동을 쉽게 하기 위한 DTO
BookDTO dto; // dto (Object : 객체)
dto = new BookDTO(title, price, company, page); // dto (Instance : 인스턴스)
// 데이터 이동
bookPrint(dto);
}
public static void bookPrint(BookDTO dto) {
System.out.println(dto.title);
System.out.println(dto.price);
System.out.println(dto.company);
System.out.println(dto.page);
}
}

View File

@@ -0,0 +1,18 @@
package object;
public class BookDTO {
public String title;
public int price;
public String company;
public int page;
public BookDTO() {
}
public BookDTO(String title, int price, String company, int page) {
this.title = title;
this.price = price;
this.company = company;
this.page = page;
}
}