Overriding means rewrite the inherited behaviors. It something�s like overwrite a file into our file system. When we a save a file name test.txt and the directory already contains a file with similar name then a message come to inform that. Anyway overriding comes into contact when a class extends another class. A class can overrides the inherited methods. Not all inherited method can be overridden. Static, final method cannot be overridden. Overriding introduce another complexity like which method implementation is bind to a method invocation. These things will be found on book.
Joined: Jan 25, 2007
Please explain me some think more as i an still confusted b/w overridding and over loading
Joined: Jan 14, 2007
In overriding method signature(method name+parameter type) need to be same but in overloading method signature must be different. Think we need square root of double, long, float, int type, then what i we could do. define different method for each data type. like for double sqdouble(double d), for int, sqrint(int i), etc. If we do that it will creates some problem, such that user of the method must know that which version of the method square root we need to call. to remove such difficulties we use overloadding. we use the same func sqr(double d), sqr(int i), etc. More on found on book.
Overloading : Having multiple methods with different method signatures( parameters + return type) , In the case of overloading , method is called upon the matching of method signature, and this will be determined at the time of compilation(Early binding/compile time polymorphism).
Overriding : This comes with point of inheritance, method name+ parameters + return type must be same as of the method in the super class which we want to override.
Overriding is done when you want to replace particular method's functionality in the subclass. JVM determines which method to call at run time.( This is called as Late binding/ Run time polymorphism).