Originally posted by Allen Sylvester:
Hi,
can super() ever have arguments?
public class Animal{
Animal(String name){ }
}
public class Dog extends Animal{
Dog()
{
super();
}
}
will the above program create an error, because class Animal does not have constructor with no arguments? If so, can super() have arguments such as super("name");
Definetly it will give you an error,super() will call Animal() construtor which does not exist, so either create a construtor like below
Animal()
{
//your code
}
call it with super() as you did in your program
or
Animal(String )
{
//your code
}
call it with super("some string")