I have an interview tomorrow and I am still confused about what happens exactly when you call super. I know that you are calling the base class constructor and it initializes the members/parameterds, but what does this imply? Does this mean that I will have access to all methods that are not private in the base class and I don't need to redefine them? I have looked in many books and websites, yet I have not really found a solid, complete way of describing what super does. What would you answer to an interviewer when he would ask you this question? I am sure he will not just be impressed by me answering, "IT calls the base class constructor, initializes parameters and it is used for inheritance purposes." I also noticed that some functions in the derived class that override the same method in the base class have the following line in the method:
return super.toString() + "This is" + name + " a" + whatevervar;
What does super.toString to as compared to if it were done a different way?
Polymorphism,
1) What is a good DEFINITION of polymorphism, not an example, to answer in an interview?
2) I noticed in a multiple level of inhertitance topic, that in a derived class that will be used by polymorphism, ex class Animal is the base class and has a method called sound. This sound method will be used polymorphically by all derived classes, ie. class Dog, class Cat, etc. I noticed in an example I have here that in class Dog (as well as the other derived classes), they have
The say that there is nothing that prevents a derived class to be used as a base class.
Before the multiple level of inheritance was discussed, they defined the sound method of class Dog as follows:
public void sound()
{
System.out.println("Woof Woof");
}
After they discussed the multiple level of inheritance, they defined both the base class Animal and the sound method in the base class as abstract and this method seemed to disappear elsewhere: ie.
public abstract class Animal
{
public abstract void sound();
....
Now how is this sound method defined in the derived classes? Same as before or not?
In this case, why did they use abstract class and not interface? I know this topic was discussed often in these forums, but here I have an example and I would like to know from this one why abstract?
Thanks for all your help!