I have the class Endereco
and the class Cliente
, I build 2 constructors for Cliente
, and one of them is to insert the client name and an object of type Endereco
, which works perfectly , but in the other constructor is to insert the name of Cliente
and create an object of type Endereco
together, the problem is that after typing the data of Endereco
, I give inspect and Endereco
is considered null .
Essential part (2 constructors) of class Address:
public class Endereco{
private String logradouro;
private String numero;
private String complemento;
private String telefone;
private String celular;
private String email;
public Endereco(String log, String num, String comp, String tel, String cel, String mail){
logradouro = log;
numero = num;
complemento = comp;
telefone = tel;
celular = cel;
email = mail;
}
public Endereco(){
Teclado t = new Teclado();
logradouro = t.leString("Informe o logradouro: ");
numero = t.leString("Informe o numero: ");
complemento = t.leString("Informe o complemento: ");
telefone = t.leString("Informe o telefone: ");
celular = t.leString("Informe o celular: ");
email = t.leString("Informe o e-mail: ");
}
}
Essential part of the Client class:
public class Cliente{
private String nome;
private Endereco endereco;
private int pontos;
public Cliente(String nm, Endereco ed){
nome = nm;
endereco = ed;
pontos = 0;
}
public Cliente(String nm){
nome = nm;
Endereco e = new Endereco();
}
}