You are here:   HomeJava ProgrammingClasses in JavaOverriding in Java
by Dinesh Thakur Category: Classes

In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.

When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version in the superclass will be hidden. If you wish to access the superclass’ version of an overridden method, you can do so by using ‘super’. 

 

In order for any particular method to override another correctly :

 

  • The return type, method name, type and order of arguments must be identical to those of a method in a parent class.
  • The accessibility must not be more restrictive than original method.

  The method must not throw checked exceptions of classes that are not possible for the original method.



Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article