java - How to write a 'get/set method' for an array of type class? -


i'm having trouble in implementation of get/set method array autores[] of type autor class same package. doesn't work in same way other variables of class :(

class autor { private string nombre; private string adscripcion;  autor(string nombre,string adscripcion) {     this.nombre=nombre;     this.adscripcion=adscripcion; } autor(){}  string getnombre() {     return nombre; } string getadscripcion() {     return adscripcion; }  void setnombre(string nombre) {     this.nombre=nombre; }  void setadscripcion(string adscripcion) {     this.adscripcion=adscripcion; } 

} public class articulo {

private string nombreart; private autor autores[]=new autor[2]; private string fechapublicacion;  articulo(string nombreart,string fechapublicacion, string nombre,string adscripcion) {     this.nombreart=nombreart;     this.fechapublicacion=fechapublicacion;     autores[0]=new autor(nombre,adscripcion);     autores[1]=new autor(nombre,adscripcion);  }   string getnombreart() {     return nombreart; } string getfechapublicacion() {     return fechapublicacion; } autor getautores() {     return autores[];//this part of code it's not correct. }   } 

the getter should like

public autor[] getautores() {     return autores; } 

and setter like

public void setautores(autor[] autores) {     this.autores = autores; } 

if use ide eclipse, menu options generate setter/getter , heaps of other things


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -