I have to create a method which tests if two object enum are equal.
Here is the code:
public Passenger{
private String name_pass;
public enum StatePass{
b,c,p
};
private StatePass state;
public Passenger(String name_pass,StatePass state){
this.name_pass=name_pass;
this.state=state;
}
public boolean isConfirmed(){
if()
return true;
return false;
}
}
Inside the if() I have to check if the field state is equals to p.
How can I do that?
You can compare enum values using ==, so your
ifcan becomeNote: in the constructor your second parameter must be a
StateClassand not aStateor you can never callthis.state=state