Created
April 5, 2020 04:27
-
-
Save parzibyte/a028c18abe4c56e1bdf32bcdd866dd7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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 Main{ | |
public static void main(String[] args){ | |
String nombre = "Luis"; | |
System.out.println("Antes de intentar cambiar la cadena: "); | |
System.out.println(nombre); | |
// Intentamos cambiar | |
intentarCambiarString(nombre); | |
System.out.println("Despues de intentar cambiar la cadena: "); | |
System.out.println(nombre); | |
int edad = 22; | |
System.out.println("Antes de intentar cambiar el entero: "); | |
System.out.println(edad); | |
// Intentamos cambiar | |
intentarCambiarInt(edad); | |
System.out.println("Despues de intentar cambiar el entero: "); | |
System.out.println(edad); | |
} | |
/* | |
String no puede cambiarse si se asigna a una nueva instancia | |
*/ | |
public static void intentarCambiarString(String cadena){ | |
cadena = "Parzibyte"; | |
} | |
/* | |
int no se puede cambiar. Es pasado por valor | |
*/ | |
public static void intentarCambiarInt(int entero){ | |
entero = 666; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment