Created
June 16, 2025 13:32
-
-
Save kurotori/a3409cc35c3c4bc77e3d66cb4a5db2ac to your computer and use it in GitHub Desktop.
Ejemplo de Sobrecarga: Sobrecarga de Método de Construcción
This file contains hidden or 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
public class App { | |
public static void main(String[] args) throws Exception { | |
Auto a1 = new Auto(); | |
a1.verDatos(); | |
Auto a2 = new Auto("VW", "Fusca"); | |
a2.verDatos(); | |
} | |
} |
This file contains hidden or 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
import java.util.Scanner; | |
public class Auto { | |
private String marca = ""; | |
private String modelo = ""; | |
/** | |
Método constructor del Auto, interactivo | |
*/ | |
public Auto(){ | |
Scanner teclado = new Scanner(System.in); | |
System.out.print("Marca: "); | |
this.marca = teclado.nextLine(); | |
System.out.print("Modelo: "); | |
this.modelo = teclado.nextLine(); | |
teclado.close(); | |
} | |
/** | |
Método constructor del Auto: directo, no interactivo | |
*/ | |
public Auto(String marca, String modelo){ | |
this.marca = marca; | |
this.modelo = modelo; | |
} | |
/** | |
Método para ver los datos del Auto creado | |
*/ | |
public void verDatos(){ | |
System.out.println("Marca: " +marca); | |
System.out.println("Modelo: " + modelo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment