public class Zoo{
public static void main (String[] args){
Animal animal1 = new Animal ("Giraffe", 5, 'M');
Animal animal2 = new Animal ("Lion", 10, 'F');
System.out.println (animal1.getName () + " " + animal1.getAge () + " " + animal1.getGender ());
System.out.println (animal2.getName () + " " + animal2.getAge () + " " + animal2.getGender ());
}
}
class Animal{
private int age;
private char gender;
private String name;
public Animal(){
this.name = "Giraffe";
this.age = 5;
this.gender = 'M';
}
public Animal (String name, int age, char gender){
this.name = name;
this.age = age;
this.gender = gender;
}
public void setName (String name){
this.name = name;
}
public String getName (){
return name;
}
public void setGender (char gender){
this.gender = gender;
}
public char getGender(){
return gender;
}
public void setAge (int age){
this.age = age;
}
public int getAge (){
return age;
}
}
Would you consider this code correct in general and to show the concept of encapsulation? Thanks :)