From: Randolph Wang <rywang@CS.Princeton.EDU>
Date: Mon, 29 Mar 2004 18:32:30 -0500 (EST)
To: mh@Princeton.EDU
Cc: randy_class@CS.Princeton.EDU
Subject: Re: question



// file 1:

public class Wave2 {
    private int N;            // number of samples per channel

    // a fake constructor
    public Wave2(int len) {
	N = len;
	// this is just to show a point, in "real code," the other fields,
	// left, and right should also be initialized.
    }

    public int wLength() {
	return N;
    }
}


// file 2:

public class TestWave2 {
    public static void main(String[] args) {

        Wave2 w = new Wave2(4);
	int i = w.wLength();
	// try uncommenting the following line--it won't compile.
	// int i = w.N;
	// it would have worked if you dump the main() method into
	// the same file, namely file1 above: because methods in the
	// same file are allowed to access private members.
	System.out.println(i);
    }
}


Re: question / Randolph Wang