I need some advice. I created three classes Om(Human), Parinte(Father) and Copil(Child). I have created constructors of this classes. In main class i have created one instance for every class. Now i stored my objects in a ArrayList. After this i will create some methods to treat my objects like sorting them A to Z by name. My question is, how to print these objects into a clear String format after i will call my sort methods cause i'm getting every time stuff like @... when i try simply to print a value stored in my collection?
My code: Om(Human) class:
public class Om {
String nume;
String prenume;
String cnp;
Om(String nume,String prenume,String cnp){
this.nume=nume;
this.prenume=prenume;
this.cnp=cnp;
}
}
My Parinte(Father) class:
public class Parinte extends Om{
String domiciliu;
Parinte(String nume, String prenume, String cnp, String domiciliu){
super(nume,prenume,cnp);
this.domiciliu=domiciliu;
}
}
My Copil(Child) class:
public class Copil extends Parinte {
int varsta;
Copil(String nume, String prenume, String cnp, String domiciliu, int varsta){
super(nume,prenume,cnp,domiciliu);
this.varsta=varsta;
}
}
And finally my main class:
import java.util.ArrayList;
import java.util.Arrays;
public class main {
public static void main(String[] args) {
Om om1=new Om("Dubolari", "Dragos", "2006004034120");
Parinte p1=new Parinte("Enache","Andrei","2006004034120","Al. Cel Bun 13");
Copil c1 = new Copil("Enache","Valeriu","2006004034120","Al. Cel Bun 13",15);
ArrayList<Om> colectie = new ArrayList<Om>();
colectie.add(om1);
colectie.add(p1);
colectie.add(c1);
}
}