10.05.2014 Views

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

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.

156 Programación I<br />

Agregar el método toString.<br />

12) Agregar al camión un motor. Indicar el código necesario para acceder y modificar dicho<br />

atributo. Anotar también código para probarlo.<br />

Agregar una variable de instancia en la clase Camión de nombre motor y los métodos de acceso<br />

y modificación. En el constructor, agregar:<br />

this.setMotor(new Motor())<br />

13) La impresión del camión debe incluir también el detalle del motor.<br />

Agregar en el método toString: this.getMotor().toString<br />

14) Al camión creado en 1), ponerle que el motor es a gasoil.<br />

Enviarle al camión el mensaje setMotorGasoil().<br />

16.8 Solución del Práctico 8<br />

Solución Práctico No. 8<br />

Tema: Herencia<br />

1)<br />

package practico8;<br />

public class Persona {<br />

private String nombre;<br />

public Persona() {<br />

this.setNombre ("Sin nombre");<br />

}<br />

public void setNombre(String unNombre) {<br />

nombre = unNombre;<br />

}<br />

public String getNombre() {<br />

return nombre;<br />

}<br />

}<br />

package practico8;<br />

public class Estudiante extends Persona {<br />

private int numero;<br />

public Estudiante() {<br />

this.setNumero(0);<br />

}<br />

public void setNumero(int unNumero) {<br />

numero = unNumero;<br />

}<br />

public int getNumero() {<br />

return numero;<br />

}<br />

@Override<br />

public String toString () {<br />

return this.getNombre() + " nro "+ this.getNumero();<br />

}

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

Saved successfully!

Ooh no, something went wrong!