Class Summary for Presentation of June 18, 1999 Topic: Modifiers Java contains about fifteen modifiers. Some of these modifiers can be applied to classes and interfaces, some to members ( methods and fields), some to fields ( variables and constants), some to variables, and many to combinations of these. To apply a modifier, you write the modifier at the left of the line declaring the item. We have already discussed and used some of the modifiers, 1. static to set up class variables, class methods, and constants 2. final to set up constants. final can be used on a class to indicate that that class cannot be extended. final can be used on a method to indicate that an extending class cannot change the definition of this method. We discussed native briefly. native can be applied to a method. If a method is native, that indicates that the implementation of that method is done in another programming language. At present, the only possible other languages are C, C++, and Ada 95. A binding for Visual Basic is being developed, but there are some incompatibilities between the two languages that must be overcome. A binding provides translation between the data types, objects, and calling methods of the two languages. We spent most of the class on the four access or visibility modifiers. These modifiers determine where a particular item may be used in your code. The four visibility modifiers are: 1. none ( called package) 2. protected 3. private 4. public Unlike C or C++, these modifiers cannot be applied to a group of items with one typing and a colon. Instead, you must explicitly place the modifier on the left of each line to which it applies. Another difference from C and C++ is the default to package visibility. These four access modifiers form a strict hierarchy in which each modifier provides access everywhere the next most restrictive modifier does and then to some additional classes. Here is the hierarchy: public: accessible to any class or interface that imports the containing class or interface of the item protected: accessible to any class and interface in the package containing the defining class or interface and to any class that inherits from the defining class package: accessible to any class or interface in the package containing the defining class or interface. private: accessible only in the defining class. Remember, however, that no access modifier can make the item more visible than its defining class or interface.