class Duck {
int pounds = 6;
float floatability = 2.1F;
String name = "Generic";
long[] feathers = {1,2,3,4,5,6,7};
boolean canFly = true;
int maxSpeed = 25;
public Duck() {
System.out.println("type 1 duck");
}
public Duck(boolean fly) {
canFly = fly;
System.out.println("type 2 duck");
}
public Duck(String n, long[] f) {
name = n;
feathers = f;
System.out.println("type 3 duck");
}
public Duck(int w, float f) {
pounds = w;
floatability = f;
System.out.println("type 4 duck");
}
public Duck(float density, int max) {
floatability = density;
maxSpeed = max;
System.out.println("type 5 duck");
}
}
public class TestDuck {
public static void main(String[] args) {
int weight = 8;
float density = 2.3F;
String name = "Donald";
long[] feathers = {1,2,3,4,5,6};
boolean canFly = true;
int airspeed = 22;
Duck[] d = new Duck[7];
d[0] = new Duck();
d[1] = new Duck(density,weight);
d[2] = new Duck(name,feathers);
d[3] = new Duck(canFly);
d[4] = new Duck(3.3F,airspeed);
d[5] = new Duck(false);
d[6] = new Duck(airspeed,density);
}
}
'개발 및 관리 > Java' 카테고리의 다른 글
final 키워드 (0) | 2013.01.21 |
---|---|
Head First Java - 9장 생성자와 가비지 컬렉션, TestHippo.java (0) | 2013.01.21 |
Head First Java - 8장 인터페이스와 추상 클래스, Of76.java (0) | 2013.01.21 |
Head First Java - 7장 상속과 다형성, TestBoats.java (0) | 2013.01.21 |
Head First Java - p.191 ArrayList6 (0) | 2013.01.19 |