Previous | Next | Trail Map | Writing Java Programs | Objects, Classes, and Interfaces


Constructors

These are the rules on constructors (and they are quite useful): private constructors() - keyword 'private' no one can instantiate your class as an object. You can still expose public static methods, and those methods can construct and object and return it, but no one else cane. package constructors() - (no attirbute on the constructor) No one outside your package can construct an instance of you. This is useful if you want to have classes in your package that can do new yourClass() but don't want to let anyone else do that. protected constructors() - keyword 'protected' only subclasses of you can use this one (any package). public constructors() - keyword 'public' the generic constructor uses these.


Previous | Next | Trail Map | Writing Java Programs | Objects, Classes, and Interfaces