return a single object in an object array

I’m new to programming and I was wondering how do you return a single object from an object array
This is the part of the code I’m having trouble in:

public Class methodName(){
    x = 3;
    if(array[x] != null){
        Class y = array[x];
    return y;

it gives me an error on the “y”

y cannot be resolved to a variable