Your problem if statement isn’t in a function, it’s just sitting in the class. You need to move it into one of your methods. Try combining your move function and your collision check.
void move() {
if (x + xa > 0)
x = x + xa;
if (y + ya > 0)
y = y + ya;
}
if (collision()){
}
}