O'Reilly logo

Software Engineering and Computer Games by Rudy Rucker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. Encapsulation, inheritance, and polymorphism

The technique of putting data and methods inside a single object is called encapsulation. The two other words most commonly used when talking about OO are inheritance and polymorphism.

The idea behind inheritance is that if you already have a class that’s almost like something you need, its a good idea to define a new class that is a child class of the existing class, recoding or overriding some of the new class methods so that they behave differently from the old class. We can draw a picture of inheritance as in Figure 4.4.

Figure 4.4. A class and a subclass

When an inherited method calls the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required