During an interview i have been asked about polymorphism. Then the interviewer asked "Can we achieve polymorphism with variable in java ?".
I tried many sources but unable to find anysuitable answer.
Plz help me guys......
During an interview i have been asked about polymorphism. Then the interviewer asked "Can we achieve polymorphism with variable in java ?".
I tried many sources but unable to find anysuitable answer.
Plz help me guys......
The simple answer to the question NO, the variables are not polymorphic in Java ie, they do not override one another. You can simply undertsand this that the variables are resolved at compile time.
Anything which is resolved at complile time,runtime polymorphism cannot be achieved using that. In java,all the methods are virtual by default,hence java exhibits Runtime Polymorphism by default regarding the methods. The question asked to you had a straightforward answer that "No,polymorphism cannot be achieved using variables in java as they are mapped at compile time"