Accessing variables in other classes (Java)

Posted by George on Stack Overflow See other posts from Stack Overflow or by George
Published on 2010-05-18T23:36:54Z Indexed on 2010/05/18 23:40 UTC
Read the original article Hit count: 114

Filed under:
|

Why doesn't the following program return 0, since I am accessing p from a new A(), which has not had main called on it?

 public class A {

         public int p = 0;

         public static void main(String[] args) {

                p = Integer.parseInt(args[0]);
                new B().go();

            }

        }


       class B {
            public void go() {
                System.out.println(new A().p);
            }
        }

© Stack Overflow or respective owner

Related posts about java

Related posts about class