java - What values are saved when creating object from same class -


say have arraylist of objects in main-class, lets dogs, , create arraylist <dog> dogs = new arraylist<dog>();

now lets in dog-class there global array of booleans:

boolean[] eyes= new boolean[2]; eyes[0] = true; eyes[1] = true; 

i create first dog in main-class, in contructor of dog, dog loses eye, , array of booleans in dog looks this:

boolean[] eyes= new boolean[2]; eyes[0] = true; eyes[1] = false; 

if go main-class , create dog, dog have 1 eye? or created 2 eyes first dog?

feel free give new title, had no idea how frase question.

edit: global mean variable created , initiated outside of constructor or other method, so:

public class dog{ boolean[] eyes= new boolean[]{true, true};  public dog(){ //... } } 

in java, variables can belong either class or instances of class. instance variables usual ones , have set in constructor or other method, , not shared @ between different instances of class. class variables declared keyword static, , shared among instances of class (a change on 1 changes all).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -