------------------------------------------------------------------------------
MC logo
Dyn Link Example
[^] Functions
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Call-by-Reference] [Call-by-Value-Result] [Call-by-Name] [Dyn Link Example] [Dyn Link Example] [C++ Translation of Java Dyn Link] [Variable Location] [Parameter Passing Method Exercise]
callex.java
class Stuff {
    private int a, b;

    private int fred(int b) {
        a = a + b;
        return 4;
    }

    private class Barney {
        private int a;
        private void sigfreid() {
            a = fred(a);
        }
        public void barney(int c) {
            a = c;
            sigfreid();
            System.out.println(a + " " + b + " " + c);
        }
    }

    public Stuff() {
        a = 2;
        b = 7;
        Barney barn = new Barney();
        barn.barney(3);
        System.out.println(a + " " + b);
    }
}

class Callex {
    public static void main(String[] argv) {
        new Stuff();
    }
}


Output is identical to the Pascal version:
4 7 3
5 7