Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Object-oriented language basics, Part 4

Inheritance: Build objects in layers

  • Print
  • Feedback

Page 7 of 10

Before leaving this topic, let's consider the keyword protected. If you declare a superclass field or method as protected, any method, declared in any class that subclasses the class that declares the protected field or method, can access that field or method. (You will see an example of protected field and method access when I present packages in a future article.)

Casting objects

Every subclass object is also a superclass object. For example, a Circle object is also a Point object. This statement implies you can assign a subclass object reference to a superclass object reference variable. Consider the following code fragment:

  • Print
  • Feedback

Resources