SE450: Java: Call by ? [17/22] Previous pageContentsNext page

What happens here?

            public class C1 {
                public void inc(int i) { i++; }
            }
            
            C1 c1 = new C1();
            int k = 1;
            c1.inc(k);
            System.out.println(k);
            
        

vs.

            public class C2 {
                public void inc(Point p) {p.x++; p.y++; }
            }
            
            C2 c2 = new C2();
            Point p = new Point(10.0,10.0);
            c2.inc(p);
            System.out.println(p);
            
        

So what is going on?

Call by reference vs Call by value vs "Call by sharing" (from Kim Bruce)

Previous pageContentsNext page