Method Overshadowing in Java

Method Overshadowing is another name given to method overriding.

In Inheritance 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.

 Here the method in the subclass is overshadowing 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.

If we want to explicitly call the method defined in the superclass then we can use the super keyword.

super.method_name  i.e the method we want to call of superclass.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s