CMSC 132A Lecture Notes - Lecture 15: Bitstream, Java Development Kit, Access Modifiers

40 views6 pages

Document Summary

You can declare some or all of a class"s methods final . You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses. The object class does this a number of its methods are final . You might wish to make a method final if it has an implementation that should not be changed and it is critical to the consistent state of the object. For example, you might want to make the getfirstplayer method in this chessalgorithm class final: class chessalgorithm { enum chessplayer { white, black } Methods called from constructors should generally be declared final. If a constructor calls a non-final method, a subclass may redefine that method with surprising or undesirable results. Note that you can also declare an entire class final. A class that is declared final cannot be subclassed. This is particularly useful, for example, when creating an immutable class like the string class.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions