# 問一個java繼承的問題(可以快點給我解答嗎??)

public class test0509

{

public static void main(String[] args)

{

Dog Amanda = new RaceDog(15, 3, 6, 20000);

Dog Bob = new RaceDog(18, 5, 7, 18000);

Dog Carol = new RaceDog(12, 4, 3, 12000);

System.out.println(Amanda.returnIndex());

>>> System.out.println(Amanda.salary_to_HI_ratio());

}

}

class Dog

{

int length, weight, age;

public Dog (){}

public Dog (int len, int wei, int a)

{

length = len;

weight = wei;

age = a;

}

public int returnIndex()

{

return length * weight / age;

}

}

class RaceDog extends Dog

{

private int salary ;

public RaceDog(int len,int wei, int a,int sa)

{

super(len,wei,a);

salary = sa;

}

public double salary_to_HI_ratio()

{

return this.returnIndex()/salary;

}

}

location:class Dog

Update:

-------------------------------------------------------

Update 2:

---------------------------------

Update 3:

Rating
• Dark
Lv 4

public class test0509

{

public static void main(String[] args)

{

RaceDog Amanda = new RaceDog(15, 3, 6, 20000);

RaceDog Bob = new RaceDog(18, 5, 7, 18000);

RaceDog Carol = new RaceDog(12, 4, 3, 12000);

System.out.println(Amanda.returnIndex());

System.out.println(Amanda.salary_to_HI_ratio());

int[] a=new int[3];

a[0]=Amanda.returnsalary();

a[1]=Bob.returnsalary();

a[2]=Carol.returnsalary();

for(int i=0;i<2;i++)

{

for(int j=i+1;j<=2;j++)

{

if(a[i]>a[j])

{

int b;

b=a[i];

a[i]=a[j];

a[j]=b;

}

}

}

System.out.print("由小到大:");

for(int i=0;i<=2;i++)

{

System.out.print(a[i]+" ");

}

}

}

class Dog

{

int length, weight, age;

public Dog (){}

public Dog (int len, int wei, int a)

{

length = len;

weight = wei;

age = a;

}

public int returnIndex()

{

return length * weight / age;

}

}

class RaceDog extends Dog

{

private double salary ;

public RaceDog(int len,int wei, int a,int sa)

{

super(len,wei,a);

salary = sa;

}

public double salary_to_HI_ratio()

{

return super.returnIndex()/salary;

}

public int returnsalary()

{

return (int)salary;

}

}

你宣告錯了　　不是Dog　　而是RaceDog

2006-05-11 10:08:58 補充：

這是1 個值啊 3.5E-4是因為你的 salary太大了而以

Source(s): ME