//class name : 사람이름
//method in class : 사람의 동작
//field in class : 사람의 속성 
public class Class1 {
	public static void main(String[] args) {
		Cat cat1;  // 클래스 변수 선언
		
		cat1=new Cat(); // 클래스 객체 생성 
		
		cat1.cry();  
		cat1.walk();
		
		Zealot zealot1=new Zealot(); //클래스 변수 선언 및 객체 생성
		Zealot zealot2=new Zealot();
		
		zealot1.attack();  // 객체(zealot1) . 메서드(attack())  
		
		/* 클래스의 메서드 등을 사용하기 위해서는
		 * 객체가 반드시 필요합니다. 
		 * 
		 *  붕어빵틀(Class) 붕어빵(객체) 
		 *  라면 - 인스턴트 식품  
		 *  클래스 class  /   객체 = instance 
		 */ 
	}
	
	public static class Cat{ //Cat 클래스 
		// 필드 , 변수 , 속성 
		int foot=4;
		int eye=2;
		String name="야옹이";
		
		// 메서드 
		public void cry(){
			System.out.println("야옹 야옹~");
			
		}
		
		public void walk(){
			System.out.println("사뿐 사뿐");
			
		}
	}
	
	public static class Zealot{
		int HP=160;
		int attackDamage=16;
		
		public void move(){			
		}
		
		public void stop(){			
		}
		
		public void attack(){	
			System.out.println("버틸 수가 없다 ");
			// 공격!! 
		}
		
		public void patrol(){			
		}
	}
}



'Java > 2012.04 강좌' 카테고리의 다른 글

7일차 Data Hiding  (0) 2012.04.12
6일차 class연습2  (0) 2012.04.10
6일차 메소드2  (0) 2012.04.10
6일차 METHOD  (0) 2012.04.10
6일차 5일차 숙제  (0) 2012.04.10

+ Recent posts