Array - 객체 배열

/*
* 객체 배열
* */
class Cat{
String name;
int age;
public Cat(String n, int a){
name = n;
age = a;
}
}

public class objectArrayTest {
public static void main(String args[]){
int i = 0;

Cat[] myCats = new Cat[5];

myCats[0] = new Cat("야옹이",2);
myCats[1] = new Cat("호동이",3);
myCats[2] = new Cat("고도리",4);
myCats[3] = new Cat("이쁜이",3);
myCats[4] = new Cat("똘똘이",2);

try{

while(i <= myCats.length ){
System.out.println(myCats[i].name +" - "+ myCats[i].age);
i++;
}

}catch(ArrayIndexOutOfBoundsException e){
System.out.println("index를 벗어나는 예외 발생.");
}catch(Exception e){
System.out.println("알 수 없는 예외 발생.");
}
}
}
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2009/10/06 23:34 2009/10/06 23:34
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/4690

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/4690

« Previous : 1 : ... 1754 : 1755 : 1756 : 1757 : 1758 : 1759 : 1760 : 1761 : 1762 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      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 29 30 31  
Statistics Graph

Site Stats

Total hits:
196670
Today:
415
Yesterday:
673