Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/05/2012, 12:16
Avatar de Patriarka
Patriarka
 
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 3 meses
Puntos: 288
Respuesta: objeto como atributo de una clase

Cita:
Iniciado por cronopiomx Ver Mensaje
en la Class Empleado, tienes protected Categoria = null; deberia ser
protected Categoria objeto, y el constructor lo inicializas en null u otra cosa..
alex
es verdad se me paso. pero me pusiste la duda en el constructor, yo lo haria asi
Código Javascript:
Ver original
  1. class Empleado {
  2.     protected int id = 0;
  3.     protected Categoria categoria = null;
  4.  
  5.     public Empleado(){}
  6.     public Empleado(int id,Categoria categoria ){
  7.         this.id = id;
  8.         this.categoria = categoria;
  9.         //SI SETEO CATEGORIA COMO NULL ENTONCES SOLO CON SETCATEGORIA
  10.         //POSRIA ASIGNARLE UN VALOR  A CATEGORIA.
  11.         //¿ESTA MAL QUE EL ATRIBUTO CATEGORIA SE INICIALICE CON NULL?
  12.     }
  13.        
  14.     public int getId(){
  15.         return this->id;
  16.     }
  17.     public int getCategoria(){
  18.         return this->Categoria;
  19.     }
  20.     public void setId(int id){
  21.         this->id = id;
  22.     }
  23.     public void setCategoria(Categoria categoria){
  24.         this->Categoria = categoria;
  25.     }
  26. }