CS 106A Lecture Notes - Lecture 20: Gobject

31 views2 pages

Document Summary

Inheritance: inheritance: a way to form new classes based on existing classes, taking on their attributes/ behavior. A way to group related classes and share code between them: one class can extend another, absorbing its data/ behavior. Examples of inheritance: java program vs. consoleprogram and graphicsprogram, gobject vs. gimage, grect, goval, gline, etc. Gobject defines the state and behavior common to all shapes. The subclasses add state and behavior unique to them. The class object: forms the root of the overall inheritance tree of all java classes. Every class is implicitly a subclass of object. How do you copy most of a class into another class, and replace other behavior with new behavior: overriding. Override: to write a new version of a method in a subclass that replaces the superclass"s version. No special syntax required to override a superclass method. Just write a new version of it in the subclass.

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