A method is said to be overridden when one is in parent class and another is in child class with the same name, same return type, same parameter.
But Here you are defining getNum() twice with same arguments(None Arguments) which should not be. Compiler will not know at run time which getNum() should be called. Methods can not be differentiated only on basis of return type.
So method should be defined only once with same name and same arguments. With same name but different arguments, you can define as many methods.
Joined: Mar 14, 2010
why am i not able to access neither the variable nor the method in the Test Class?
I have made a an object 's' but i am not able to access "i". What is wrong here?
The problem isn't in accessing the field, the problem is you are trying to execute code directly in a class body. Code can only be executed in a constructor, initializer or method. Try putting that code into a main method instead.
Oh, and before you ask: you cannot override static methods or fields, only non-static methods. Static methods and fields will hide or shadow the equally named method / field from the super class. For these shadowing methods / fields the reference type is used, not the actual type. So in your example it will access the superClass version of i, not the subClass version.