public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal a=new Animal();
a.speak();
Animal d=new Dog();
d.speak(3);//
}
class Animal
{
public float speak()
{
System.out.println("I am a animal!");
return 0;
}
}
class Dog extends Animal
{
public double speak(int a)
{
System.out.println("Dog sparks!");
return 0;
}
}
}
I just learned override and overload in java. Here what i am trying to do is to implement a overload.But the compiler shows that d.speak(3) is wrong.
I think the dog inherit the animal. So it has a speak() func. And I add a speak(int) to overload. Why I am wrong? thank u.