1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
class Product03{
private String name;
private int price;
private int cnt;
public Product03(String name, int price, int cnt) {
this.name = name;
this.price = price;
this.cnt = cnt;
}
public int buyInfo() {
System.out.print(name+"\t"+price+"\t"+cnt+"\t"+(price*cnt)+"\n");
return price*cnt;
}
}
public class A12_ObjVSMultiObjAns {
public static void main(String[] args) {
Product03 pr = new Product03();
System.out.println(pr.buyInfo());
}
}
|
cs |
buyInfo()메서드를 유심히 보자.
출력값이 2개다. print값과 return값.
이런거 처음봤다.
여태까지 메서드에 print가 있으면 return은 쓰면 안되고
반대로 return이 있으면 print를 쓰면 안되는 줄 알았다.
근데 이게 왠걸. 되네.
메인메서드에서 출력해보니까 둘다 나오네.
게다가 인트 메서드이니 더하고 빼고 할 수 있네.(리턴값만 영향받음) 신긔신긔
이건 까먹은게 아니라 그냥 몰랐던 것.
근데 복습을 통해 알게됨 ㅎ_ㅎ ;; 결론은 복습최고
'JAVA > 되새김질' 카테고리의 다른 글
향상된 for문 Iterator (0) | 2019.08.18 |
---|---|
객체지향 복습(4) ─ 1:다 (Obj vs MultiObj) (0) | 2019.08.18 |
객체지향 복습(3) ─1:1 (Obj vs Obj) + 객체 사용 (0) | 2019.08.17 |
야구 스코어 만들기 (0) | 2019.08.16 |
this에 대한 고찰 (0) | 2019.08.15 |