SHARE
TWEET

Instanciar Objeto desde otra clase

salejan Jun 5th, 2020 684 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package clases_y_objetos;
  7.  
  8. /**
  9.  *
  10.  * @author JUAN
  11.  */
  12. public class Persona {
  13.    
  14.    String nombre;
  15.    String telefono;
  16.    int edad;
  17.    
  18.    public Persona (String nom, String tel, int edad){
  19.        this.nombre = nom;
  20.        this.telefono = tel;
  21.        this.edad = edad;
  22.    }
  23.    
  24.    public void mostrarPersona(){
  25.        System.out.println("Persona creada: \n"+
  26.                            "Nombre: "+this.nombre+
  27.                            ", Telefono: "+this.telefono+
  28.                            ", Edad: "+this.edad);
  29.    }
  30.    
  31. }
  32.  
  33.  
  34. //----------------------------------------------------------------------------------------------------------------------------
  35.  
  36. /*
  37.  * To change this license header, choose License Headers in Project Properties.
  38.  * To change this template file, choose Tools | Templates
  39.  * and open the template in the editor.
  40.  */
  41. package clases_y_objetos;
  42.  
  43. /**
  44.  *
  45.  * @author JUAN
  46.  */
  47. public class Agenda {
  48.    
  49.     public static void main(String[] args) {
  50.        
  51.         //se crean las personas
  52.         Persona personaUno = new Persona("Pablo Ruiz Montes", "1234567890", 43);
  53.         Persona personaDos = new Persona("fabiola Rios castro", "0987654321", 23);
  54.        
  55.         //Se muestran las personas
  56.         personaUno.mostrarPersona();
  57.         personaDos.mostrarPersona();
  58.        
  59.     }
  60.    
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top