Cumulative Project 4 - Game Logic Part II

The exercise of the project is :

Hello everyone, I am learning java. Inside the onAnswerSubmission() function I cannot understand how the variable currentQuestion saves the object returned by the getCurrentQuestion() function. And then, I cannot understand how isCorrect() function takes the information to validate.
Thank you in advance :grinning:

Here is my code in and

public class MainActivity {

    // TODO #1: add integer member variables here
int currentQuestionIndex;
int totalCorrect;
int totalQuestions; 

    // TODO #2: add ArrayList member variable here
ArrayList<Question> questions = new ArrayList<Question>();

    // TODO #3 add startNewGame() here    
public void startNewGame(){
  questions = new ArrayList<Question>();
 Question question_1 = new Question(268514,"How long have not been working?","Six months","Three months","Eighteen months","Twelve months",2);
 Question question_2 = new Question(314903,"When is my birthday?","August 19","Abril 3","December 11","July 28",0); 
 Question question_3 = new Question(631755,"How long has your relationship been longest?","12 months","3 months","10 days","40 months",3);
totalCorrect = 0;
totalQuestions = 0;
Question firstQuestion = chooseNewQuestion();
// displayQuestion(firstQuestion);

    int generateRandomNumber(int max) {
      double randomNumber = Math.random();
      double result = max * randomNumber;
      return (int) result;

    // TODO #4 add chooseNewQuestion() here
public Question chooseNewQuestion(){
int n = questions.size();
int randomNumber = generateRandomNumber(n-1);
currentQuestionIndex = randomNumber;
return questions.get(currentQuestionIndex);
    // TODO #5 add getCurrentQuestion() here
public Question getCurrentQuestion(){
  return questions.get(currentQuestionIndex);
    // TODO #6 add onAnswerSubmission() here
public void onAnswerSubmission(){
  Question currentQuestion = getCurrentQuestion();
    totalCorrect += 1;
  if (questions.size()==0){
    System.out.println("Game over");

public class Question(){
public class Question {
    int imageId;
    String questionText;
    String answer0;
    String answer1;
    String answer2;
    String answer3;
    int correctAnswer;
    int playerAnswer;

    public Question(int imageIdentifier,
      String questionString,
      String answerZero,
      String answerOne,
      String answerTwo,
      String answerThree,
      int correctAnswerIndex) {
        imageId = imageIdentifier;
        questionText = questionString;
        answer0 = answerZero;
        answer1 = answerOne;
        answer2 = answerTwo;
        answer3 = answerThree;
        correctAnswer = correctAnswerIndex;
        playerAnswer = -1;

    boolean isCorrect() {
      return correctAnswer == playerAnswer;