array required but [ClassName] found java

I’m trying to write a function checking if 2 arrays are equal.

public class DynamicArray {
    private int size; // stores the number of “occupied” elements in the array
    private int[] array; 


    boolean equals(DynamicArray obj) {
        boolean keepChecking = true;
        int objSize = 1;
        for (int i = 0; i < obj.length; i++) {
            if (obj[i] == 0 && keepChecking) {
                keepChecking = false;
                objSize = obj[i];

        if (size != objSize) 
            return false;

        for (int i = 0; i < size; i++) {
            if (array [i] != obj [i]) {
               return false;
        return true;

The thing is that array might be partially filled array, not filled elements will be just zeros. So, to check if 2 arrays are equal, first, I find the size of the occupied array and then I do all the checkings.

So, every time I’m trying to get the value of obj[i] or obj.length it keeps showing the error “array required, but DynamicArray found.” for obj[i] and “cannot find symbol n symbol: variable length n location: variable obj of type DynamicArray” which I don’t understand because the other array is also DynamicArray type

public class ArrayDemo {

    public static void main(String[] args) {
        DynamicArray ar1 = new DynamicArray(1);
        DynamicArray ar2 = new DynamicArray(1);

        System.out.println("equals() is " + ar1.equals(ar2));