Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 5, 2020 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5e85796cfa122f058f0fa8e51b67f5d9 to your computer and use it in GitHub Desktop.
Save parzibyte/5e85796cfa122f058f0fa8e51b67f5d9 to your computer and use it in GitHub Desktop.
/**
En Java, ¿se pasa por referencia o por valor?
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
Copyright (c) 2020 Luis Cabrera Benito
Licenciado bajo la licencia MIT
El texto de arriba debe ser incluido en cualquier redistribución
*/
class Mascota{
private String nombre;
public Mascota(String nombre){
this.nombre = nombre;
}
public void setNombre(String nombre){
this.nombre = nombre;
}
public void saludar(){
System.out.println("Guau! me llamo " + this.nombre);
}
}
class Main{
public static void main(String[] args){
Mascota m = new Mascota("Maggie");
System.out.println("Antes de intentar cambiar el nombre...");
m.saludar();
// Intentar cambiar nombre
intentarCambiarNombre(m);
System.out.println("Despues de intentar cambiar el nombre...");
m.saludar();
}
/*
Demostración de que el objeto se puede cambiar desde otra función
*/
public static void intentarCambiarNombre(Mascota unaMascota){
unaMascota.setNombre("Guayaba");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment