Java, how to use methods and constructor of the extended class

Let’s suppose you are working on class Extending which extends the class Base.
Now you want to overwrite method setName(name) but you also want to execute the code within the overwritten method plus some custom code, then just call within the Extending class

super.setName()
customcode();

If you need to do the same for the constructor just call

super()

if the extended constructor has no arguments, otherwise

super(name, surname, age, sex)
Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...