article thumbnail image
Published 2022. 10. 26. 16:32

1.클래스 선언

클래스 선언구문에 작성가능한 접근제한자(public , default(접근제한자 생략))          
- public : 같은 패키지내에서든 다른 패키지에서든 해당 클래스 사용 가능
- default : 같은 패키지 내에서만 사용가능 (다른 패키지에서는 사용불가)

  2. 클래스 다이어 그램 
 
   

 

 

3. 클래스 예시 

public class Product { 
    private String pName; //productName
	private int price;
	private String brand;
	
	//기본생성자
	public Product() {
		
	}
	//매개변수 생성자 
	public Product(String pName,int price,String brand) {
		this.pName = pName;
		this.price = price;
		this.brand = brand;	
	}
	
     //메소드부
	//public void setPName(String pName) {(x)
	             //setPname(X)
	public void setpName(String pName) {
		this.pName = pName;
	}
	public void setPrice(int price) {
		this.price = price;
	}	
		public void setBrand(String brand) {
		this.brand = brand;
	}
	
	public String getpName() {
		return pName;
	}
	public int getPrice() {
		return price;
	}
	public String getBrand() {
		return brand;
	}
	
	public String information() {
		return "pName : "+pName + ", price : " + price + ", brand : "+ brand;
	}
}

'JAVA' 카테고리의 다른 글

6_5. 객체_ 생성자  (0) 2022.10.27
6_4. 객체 _필드  (0) 2022.10.26
6_2 . 객체 캡슐화 (setter/getter)  (0) 2022.10.26
6_1. 객체란  (0) 2022.10.26
5_2. 배열의 복사(ArrayCopy)  (0) 2022.10.25
복사했습니다!