CMSC 132 Lecture Notes - Lecture 5: Vista-Class Cruise Ship, Instance Variable
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( )