GNU Java Training Wheels 1.1: Moving a class into a sub-package

Next: Importing a package, Previous: Moving a class into a package, Up: Packages in J.T.W. and Java [Contents][Index]

### 5.2 Moving a class into a sub-package

Suppose you want to move a class `A` from no package (the folder `~/jtw-tutorials`) to a package called for argument’s sake `pkg.inner`, the steps from Moving a class into a package needs to be followed, the only difference being that the `package` spec needs to be changed to ``package` pkg.inner;` and the file needs to be moved into the folder `pkg/inner`. To run the `class` file you need to invoke the following Make command:

`make clean pkg/inner/A.run`.

Here is the class definition for the file `~/jtw-tutorials/pkg/inner/A.jtw`:

    package pkg.inner;

    public class A
    begin
        public property int data;

        public classVar int data2 = 666;

        public constructor A(int d)
        begin
            data = d;
        end

        public method void meth1()
        begin
            System.out.println("meth1:" + data);
        end

        public method void meth2()
        begin
            System.out.println("meth2:" + data);
        end

        public function void func()
        begin
            System.out.println("func:" + data2);
        end

        beginMain
            var A a1 = new A(123);
            a1.meth1(); // prints out "meth1:123"
            var A a2 = new A(456);
            a2.meth2(); // prints out "meth2:456"
            A.func(); // prints out "func:666"
        endMain
    end