0% found this document useful (0 votes)
22 views1 page

Overriding

Method overriding occurs when a subclass implements a method that is already implemented in a superclass, with the same method name and compatible parameter and return types. For example, a USATimer subclass could override the getDate method from the Timer superclass by using a USA parameter type that extends the Country parameter type in the superclass.

Uploaded by

Gautam Sai Teza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Overriding

Method overriding occurs when a subclass implements a method that is already implemented in a superclass, with the same method name and compatible parameter and return types. For example, a USATimer subclass could override the getDate method from the Timer superclass by using a USA parameter type that extends the Country parameter type in the superclass.

Uploaded by

Gautam Sai Teza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Page 1 of 1

Method Overriding
Method overriding occurs when a subclass implements a method that is already implemented in a
superclass. The method name must be the same, and the parameter and return types of the subclass's
implementation must be subtypes of the superclass's implementation. You cannot allow less access than
the access level of the superclass's method.
eg,
class Timer {
public Date getDate(Country c) { ... }
}
class USATimer {
public Date getDate(USA usa) { ... }
}

Where Usa extends Country.


See the Sun Tutorial, Overriding for more information.

You might also like