Oi Geovane, supondo que você tem uma Classe Aluno e tem os atributos :
int id;
String nome;
Quando lá no Main.java você criou um novo Aluno, com Aluno novoAluno = new Aluno();
e fez um syso(aluno);
Como a classe aluno não tem a implementação de toString();
então será chamado a implementação de toString da classe Object, que é pai de todas as classes do Java,
logo no console será impresso: Aluno:h123h232 (nr qualquer)
Porque eu sei que será impresso: Aluno:h123h232 (nr qualquer)
Pq eu vi na documentação a implementação do toString da classe Object
Mas se você quiser deixar o toString mais enteressante pra vc, basta implementar na classe Aluno.
@Override
public String toString() {
return nome;
}
E como a implementação está dentro do Aluno, então vc pode customizar:
@Override
public String toString() {
return "Nome: "+ nome + " - Id: " + id ;
}
Espero ter ajudado a compreender, talvez seja difícil agora, mas tente entender com a documentação também:
https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()
Public String toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Returns:
a string representation of the object.