CPSC 233 Lecture 6: 5Feb

42 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents