WUSTL CSE 131 - sp14_10 (19 pages)

Previewing pages 1, 2, 3, 4, 5, 6 of 19 page document View the full content.
View Full Document

sp14_10



Previewing pages 1, 2, 3, 4, 5, 6 of actual document.

View the full content.
View Full Document
View Full Document

sp14_10

316 views


Pages:
19
School:
Washington University in St. Louis
Course:
Cse 131 - Computer Science I
Computer Science I Documents

Unformatted text preview:

CSE 131 Computer Science 1 Module 10 Hierarchies class inheritance and class hierarchies Classes Inheritance Classes may form a hierarchy general specific Capture common features in a general class Java allows such hierarchy a new class can extend an existing class the new class is called the subclass the original is called the superclass the subclass inherits all data and methods in its superclass Access permissions for subclass private instance variables and methods can only be accessed within the class they belong to protected instance variables and methods can be accessed by subclasses Shape lineColor lineStyle OneDim TwoDim startStyle endStyle Line Curve p1 p2 p fillColor Rect Ellipse center width height radius1 radius2 To extend a class use the extends keyword public class Ellipse extends twoDim Using inherited methods Superclass has a method foo A subclass can use foo without defining it itself A subclass can override a method from a superclass Superclass has foo a subclass can re define and thus override foo can access superclass version of a method foo as super foo A subclass constructor may invoke its superclass constructor using super Abstract Methods and Classes A class can claim an abstract method without defining it Leave it for its subclass to define A class with one or more abstract methods is called an abstract class and must be labeled abstract public abstract class twoDim extends Shape public abstract double area public class Rect extends twoDim double width height public double area return width height One cannot create objects belonging to an abstract class but can create objects belonging to concrete subclasses a concrete subclass of an abstract class must define all abstract methods of its superclasses Abstract Methods and Classes An abstract method is a method that is identified in a superclass and defined in its subclasses A class with one or more abstract methods is called an abstract class and must be labeled abstract public abstract class



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view sp14_10 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view sp14_10 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?