Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an array to constructor?

I'm trying to learn Java, but I have a problem with passing an array to constructor. For example:

Application class: byte[][] array = new byte[5][5]; targetClass target = new targetClass(array[5][5]);

Target class:

public class targetClass {
    /* Attributes */
    private byte[][] array = new byte[5][5];

    /* Constructor */
    public targetClass (byte[][] array) {
        this.array[5][5] = array[5][5];
    }

}

I'd greatly appreciate it if you could show me how I can do that.

like image 775
bbalchev Avatar asked Dec 09 '22 04:12

bbalchev


1 Answers

First, usually class names in Java starts with Upper case, now, to the problem you met, it should be:

public class TargetClass { /* Attributes */ 
    private byte[][] array;

    /* Constructor */
    public TargetClass (byte[][] array) {
        this.array = array;
    }
}
like image 72
MByD Avatar answered Dec 11 '22 17:12

MByD