These methods are setter and getter as they help you initialize and retrieve value from an Object to which they are related to, hence the prefix of each method
private void setQuestion(String str){ question = str;}
public String getQuestion(){ return question;} depending on project requirement you will make setter private or public, where getter is usually public.
In original code there is call for initializeTest() method that looks like this
private void initializeTest()
{
test[0] = new Test("Question 1 to ask", "I like A", "I like B", "I like C", "I like B");
test[1] = new Test("Question 2 to ask", "I like A", "I like B", "I like C", "I like A");
test[2] = new Test("Question 3 to ask", "I like A", "I like B", "I like C", "I like C");
}
in this method with every call for new Test a new object of type Test is created and because arguments been provided newly created object is automatically initialized with these arguments. The initialization take place in the constructors like in our case in this one
public Test(String quest, String oA, String oB, String oC, String ans)
{
setQuestion(quest);
setOptionA(oA);
setOptionB(oB);
setOptionC(oC);
setAnswer(ans);
}
where with the help of setter methods we initialize every variable of the Test object. If the setter method would be public instead of private we could do something like this
test[0] = new Test();
test[0].setQuestion("Question 1 to ask");
test[0].setOptionA("I like A");
test[0].setOptionB("I like B");
test[0].setOptionB("I like B");
test[0].setAnswer("I like B");
but this would be time consuming if we want to initialize more one object.
Getter method
public String getQuestion(){ return question;} as you see return value of associated variable. These been used here
private void setTest()
{
titleLabel.setText("Question No. " + (qNum+1));
questionNumLabel.setText((qNum+1)+"/3");
questionLabel.setText(test[qNum].getQuestion());
jrbA.setText(test[qNum].getOptionA());
jrbB.setText(test[qNum].getOptionB());
jrbC.setText(test[qNum].getOptionC());
qNum++;
if(qNum == 3)
{
nextButton.setText("SUBMIT");
}
} More about how classes works, members variable declaration, defining methods and more could be found
here