Q:

Java: setting a bool for all instances of a class

I searched some times but didn't get a clue.
I'm trying to set up a directed graph. Each node (instance of the class Node) should hold a bool visited to see if it was visited by a search function.
After the search is completed i want to reset the bool visited for all instances of the class without running through them again. 
Is there some way i can go - or am I totally on the wrong track?
Thanks for help and cheers,
Mike
// Cans.java
public class Cans {
    public static void main(String[] args) {
        int[] fillLevels = {2,15,3};
        int[] states = {8,0,0};

        node MyNode = new node(3,0);
        MyNode.setfillLevels(fillLevels);

        node MyLink = new node(3,1);

        MyNode.addLink(MyLink);

        MyNode.setStates(states);

        MyLink.printStates();

        System.out.println("Number of links: "+MyNode.getNumLinks());
    }

    boolean fillState(node nodeA, int stateA,node nodeB, int stateB){
        int value = nodeA.getState(stateA);
        nodeA.setState(stateA, value);
        return true;
    }

}

..
// node.java
    import java.util.*;

    public class node {
        private int[] states;
        private static int[] fillLevels;
        private int level;
        private int n_nodes;
        private static int id0 = 0;
        private int id;
        private boolean visited;

        List<node> next = new ArrayList<node>();

        node(int n_nodes,int level){
            id=id0;
            id0++;
            this.n_nodes = n_nodes;
            this.level = level;
            states = new int[n_nodes];
            visited = false;
            fillLevels = new int[n_nodes];
        }

        void setfillLevels(int[] fillLevels){
            this.fillLevels = fillLevels;
        }

        void setStates(int[] states){
            this.states = states;
        }   

        void setState(int state, int value){
            states[state] = value;
        }

        int getState(int state){
            return states[state];
        }

        void addLink(node linkedNode){
            next.add(linkedNode);
        }

        boolean isVisited(){
            return visited;
        }

        int getNumLinks(){
            return next.size();
        }

        void printStates(){
            System.out.println("States of node #"+id+" on level "+level+":");
            int cntr = 0;
            for(int i:states){
                System.out.println(cntr+": "+i);
                cntr++; 
            }
        }
    }

A:

Don't add boolean flag to the node. It is not a stored property of the node, but a transient property of the algorithm that you are running on it.
Instead, keep a separate set of visited nodes, and pass it around in an additional parameter as you run your algorithm:
Set<Node> visited = new HashSet<>();

Instead of setting node.visited = true, use visited.add(node). Instead of checking if (node.visited) ... use if (visited.contains(node)) ...
This approach lets you reset all visited "flags" at once by calling visited.clear().

