CMSC 132 Lecture Notes - Lecture 5: Vista-Class Cruise Ship, Instance Variable

115 views4 pages

Document Summary

Another reason why we need inheritance: for abstract classes. Ex: the shape class: picture consists of array shapes of type shape[ , to draw the picture, invoke drawme( ) for all shapes. Shapes[1] = new rectangle( ); for ( int i = 0; i < shapes. length; i++ ) shapes[i] //draws all the shapes. each shape invokes drawme() for that particular shape. Derive various subclasses for specific shapes. Shape object does not represent a specific shape, still users can create instances of it (shape s = new shape();) Behaves much like method in interface. Give a signature, but no body. Includes modifier abstract in method signature. Cannot be created using new shape s = new shape( ); // illegal! Inheritance is but one way to create a complex class from another. the other way is to explicitly have an instance variable of the given object type. this is called composition. Public class obja { public methoda( )

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