Basically, I would like to know why the static method cannot be obscured by the instance method (I know why this will lead to ambiguity in certain circumstances), while the static variable can be obscured by the instance variable (it applies only to subclasses).
Example:
public class Apartment{ static int area = 10; public static int getArea(){ return area; } } class BedroomFlat extends Apartment { int area = 10;
So, if I tried to declare an int area (instance variable) along with a static int area in the superclass, it will throw an error, but this will not happen if declared in the subclass, even if the static int area is still displayed from the subclass.
What exactly is the difference in behavior between trying to shadow a static method using an instance method and trying to shadow a static variable in an instance variable.
Thanks in advance.
source share