1
votes

I am new to java and I am trying to work a simple program. I have created a class and defined the variables like this

public class Animal {

    private String age;
    private String color;
    Breed breed;

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Breed getBreed() {
        return breed;
    }

    public void setBreed(Breed breed) {
        this.breed = breed;
    }
}

class Breed {
    private String afador;
    private String afaird;
    private String aussiepom;

    public String getAfador() {
        return afador;
    }

    public void setAfador(String afador) {
        this.afador = afador;
    }

    public String getAfaird() {
        return afaird;
    }

    public void setAfaird(String afaird) {
        this.afaird = afaird;
    }

    public String getAussiepom() {
        return aussiepom;
    }

    public void setAussiepom(String aussiepom) {
        this.aussiepom = aussiepom;
    }
}

I want to access the variables in class "BREED" from ANOTHER file, with "animal.breed..." which does not work. How can I access the variables in the "BREED" class?? I am not sure if it is because I have the getter and setters in this file, kindly advise on the same.

that's why you have a getter method. "does not work" is not helpful, post a minimal reproducible example including errors. - OldProgrammer
Java is case sensitive, so Breed is not BREED and there is no such this as JAVA. Where do you try to access the data from Breed? Show the code you're having trouble with. - David Conrad