CPSC 233 Lecture 6: 5Feb
Document Summary
All ields and methods are accessible to code within the class itself. Access from other classes is controlled with these keywords: public, protected, private, package-private accessible wherever the class is visible accessible only to the class and its subclasses hidden from all other classes. Other classes should get and set these values with public accessor methods . If a variable should be directly accessible from a subclass use protected. It is usually beter for subclasses to use accessor methods: declare methods public. Occasionally, non-public methods are appropriate: declare classes public. Occasionally, a more limited visibility is appropriate. Must be deined for at least one class in a program. Each class in an applicaion can have its own main() method: useful for tesing a class in isolaion. When you run a class with java classname, its bytecode is loaded, and execuion starts at its main(: other classes are loaded as needed, but their main() method are not used.