The problem is that TestA cannot access Process.write(). The access modifier private means that only Process objects can access that method. There are two ways to fix it. First, you can change Process.write to any other access modifier at all (public, protected, and default/package). Since TestA is both a subclass and in the same package, it would be allowed to access the method. The other option is to store/cast 't' as/to a TestA object, where write can be accessed by main(). Process t = new TestA(); //1 ((TestA) t).write(); System.out.println(t.s); or TestA t = new TestA(); //1 t.write(); System.out.println(t.s); or private void write() -> public/protected/nothing void write() [This message has been edited by David Garland (edited August 12, 2001).]
I always thought what methods are available is determined by the actual object type. For instance, Object object = new String("Hi!"); object.toString() will return "Hi!" and not some hashing mumble jumbles. But here it seems like it is also determined by the reference type. Can someone shed some light on as to what are determined by the actual object type and what are determined by the reference type? Thanks.
Cameron, private methods do not particiate in inheritance, because the are invisible to the subclasses. This is precisely why, the program says that it can't find method write() in class Process - it is simply invisible to everything outside the class.