- 클래스 변수는 해당 클래스의 모든 인스턴스에서 같은 값을 가지는 것.
- 인스턴스 변수는 각각의 인스턴스 마다 다른 속성을 가지는 것.
- 책의 예제는 트럼프 카드
- 클래스 변수 - 카드의 크기
- 인스턴스 변수 - 기호 모양(하트, 클로버...), 숫자
- 신발
- 클래스 변수
- 인스턴스 변수
- 조던 1 시카고, 블랙토.. , 이지 350,700... , 덩크 ... ,
- 사이즈
package ch6;
public class ShoesTest {
public static void main(String[] args) {
System.out.println("Maker : "+Shoes.maker);
System.out.println("Model : "+Shoes.model);
Shoes s1 = new Shoes();
s1.edition = "chicago og";
s1.size = 8;
Shoes s2 = new Shoes();
s2.edition = "pine green";
s2.size = 9;
System.out.println("First Shoes are ("+s1.maker+", "+s1.model+" "+s1.edition+"), size is "+s1.size);
System.out.println("First Shoes are ("+Shoes.maker+", "+Shoes.model+" "+s2.edition+"), size is "+s2.size);
System.out.println("Change jordan to yeezy");
s2.maker = "adidas";
s2.model = "yeezy boost";
System.out.println("Maker : "+Shoes.maker);
System.out.println("Model : "+Shoes.model);
Shoes s3= new Shoes();
s3.edition = "350";
s3.size = 8.5;
System.out.println("First Shoes are ("+Shoes.maker+", "+Shoes.model+" "+s3.edition+"), size is "+s3.size);
}
}
class Shoes{
static String maker = "nike";
static String model = "jordan1";
String edition;
double size;
}