Question: What are the differences between method overloading and method overriding?
Answer: Overloaded Method Overridden MethodArguments Must change Must not changeReturn type Can change Can’t change except for covariant returnsExceptions Can change Can reduce or eliminate. Must not throw new or broader checked exceptionsAccess Can change Must not make more restrictive (can be less restrictive)Invocation Reference type determines which overloaded version is selected. Happens at compile time. Object type determines which method is selected. Happens at runtime.
Overloaded Method Overridden MethodArguments Must change Must not changeReturn type Can change Can’t change except for covariant returnsExceptions Can change Can reduce or eliminate. Must not throw new or broader checked exceptionsAccess Can change Must not make more restrictive (can be less restrictive)Invocation Reference type determines which overloaded version is selected. Happens at compile time. Object type determines which method is selected. Happens at runtime. Source: CoolInterview.com
Rules to Post Answers in CoolInterview.com:- There should not be any Spelling Mistakes. There should not be any Gramatical Errors. Answers must not contain any bad words. Answers should not be the repeat of same answer, already approved. Answer should be complete in itself.
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.