07.06.2013 Views

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

Classi astratte ed interfacce - Dipartimento di Ingegneria Informatica ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A. Longheu – Linguaggi M-Z – Ing. Inf. 2009-2010<br />

<strong>Classi</strong> <strong>astratte</strong> - Esempio<br />

public abstract class AnimaleTerrestre extends Animale {<br />

public AnimaleTerrestre(String s) {super(s); }<br />

public String vive() {return "sulla terraferma"; }<br />

public String chi_sei()<br />

{return "un animale terrestre"; }<br />

}<br />

public abstract class AnimaleAcquatico extends Animale {<br />

public AnimaleAcquatico(String s) {super(s); }<br />

public String vive() {return "nell'acqua"; }<br />

public String chi_sei() {<br />

return "un animale acquatico"; }<br />

}<br />

Due meto<strong>di</strong> astratti su tre sono ridefiniti, ma uno è ancora astratto<br />

quin<strong>di</strong> la classe è ancora astratta<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!