[Solved] Is Setters can have more than one argument? If it’s how it useful? [closed]


Setter usually refers to a method which sets the value of one class variable. So it needs only one parameter. If you want a method which sets the values of two class variables you can do that of course but that’s not usually what is meant by setter.

Based on additional question asked by OP, I think he needs something like this.

    public class Test001 {

        private int x;

        private int y;

        public int getX() {
            return x;
        }

        public void setX(int x) {
            this.x = x;
        }

        public int getY() {
            return y;
        }

        public void setY(int y) {
            this.y = y;
        }

        public void setXY(int x, int y) {
            setX(x);
            setY(y);
        }

        public int[] getXY() {
            return new int[] { x, y };
        }

    }

3

solved Is Setters can have more than one argument? If it’s how it useful? [closed]