Q.1 Here is the inheritance structure:
Any why the above code generate the error:
java:26: non-static variable this cannot be referenced from a static context. Which one is non-static and which one is static content?
Q.2 Polymorphic arguments (same as above hierarchy)
In the Employee class:
public TaxRate findTaxRate(Employee e)
{
.....do calculation and return tax rate
}
Manager m = new Manager();
.
.
Taxrate t = findTaxRate(m); //What does this statement mean? to calculate Manager's tax rate?? So, a subclass's object can be passed to the parent class's function??
Is there any direction (upward or downward) among the hierarchy of classes for passing the object reference?
Q.3 instanceof
e.g.
So, for a downward direction, if Employee's object (parent class) wants to access to the Manager's attributes (subclass), it has to use instanceof and cast the Employee's object, e.g.
public void method(Employee e) { //Where is this method? in another class? or same class of Employee?
I don't undestand when should I use instanceof and casting object? Why should I use it as Employee e = new Manager(); or new Director(); (The subclass object can be instantiated along the hierarchy). or instanceof is used when the subclass is inherited HORIZONTALLY.
Thanks a lot
Andrew
(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited December 14, 2001).]