Chapter 11 -- Inheritance Jim Burns. The Concept of Inheritance Since day one, you have been creating classes and instantiating objects that are members.

Slides:



Advertisements
Similar presentations
More on Classes Inheritance and Polymorphism
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
9. Inheritance 9.1 Subclasses 9.2 Polymorphism 9.3 Abstract Classes 9.4 Modifiers and Access 9.6 Object-Oriented Design with Use Cases and Scenarios.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Understanding Inheritance Object-Oriented Programming Using C++ Second Edition 9.
Unit 011 Inheritance Recall What Inheritance is About The extends Keyword The Object Class Overriding versus Overloading What is Actually Inherited? Single.
Chapter 10 Classes Continued
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
1 Introduction to Inheritance Overview l Inheritance ensures Reusability l Example of Inheritance l What is actually Inherited? l Overloading Vs. Overriding.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Chapter 8 More Object Concepts
1 Abstract Class There are some situations in which it is useful to define base classes that are never instantiated. Such classes are called abstract classes.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
What is inheritance? It is the ability to create a new class from an existing class.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
CSC 142 Computer Science II Zhen Jiang West Chester University
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Chapter 12 Advanced Inheritance
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Chapter 7 Understanding Inheritance. LOGO Objectives  Learn about inheritance and its benefits  Create a derived class  Learn about restrictions imposed.
CSC 205 Java Programming II Inheritance Inheritance In the real world, objects aren’t usually one-of-a-kind. Both cars and trucks are examples of.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Programming Fundamentals1 Chapter 8 OBJECT MANIPULATION - INHERITANCE.
1 CS 177 Week 11 Recitation Slides Class Design/Custom Classes.
1 The finalize, clone, and getClass Methods  The finalize method is invoked by the garbage collector on an object when the object becomes garbage.  The.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
More Object Concepts— Farrell, Chapter 4 Dr. Burns.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Inheritance ndex.html ndex.htmland “Java.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
BY:- TOPS Technologies
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Modern Programming Tools And Techniques-I
Inheritance and Polymorphism
Week 8 Lecture -3 Inheritance and Polymorphism
Modern Programming Tools And Techniques-I Inheritance
Understanding Inheritance
Inheritance Chapter 5.
Java Programming Language
Chapter 9: Polymorphism and Inheritance
Java – Inheritance.
Inheritance Inheritance is a fundamental Object Oriented concept
Java Programming, Second Edition
Inheritance.
Chapter 9 Carrano Chapter 10 Small Java
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

Chapter Inheritance Jim Burns

The Concept of Inheritance Since day one, you have been creating classes and instantiating objects that are members of those classes. Since day one, you have been creating classes and instantiating objects that are members of those classes. Programmers use a graphical language to describe classes and object-oriented processes—this Unified Modeling Language consists of many types of diagrams Programmers use a graphical language to describe classes and object-oriented processes—this Unified Modeling Language consists of many types of diagrams

Class diagram Is a visual tool that provides you with an overview of a class Is a visual tool that provides you with an overview of a class It is a rectangle divided into three sections It is a rectangle divided into three sections the top section contains the name of the classthe top section contains the name of the class The middle section contains the names and data types of the attributesThe middle section contains the names and data types of the attributes The bottom section contains the methodsThe bottom section contains the methods

The Employee class diagram Employee -empNum : int -empNum : int -empSal : double -empSal : double +getEmpNum : int +getEmpNum : int +getEmpSal : double +getEmpSal : double +setEmpNum(int num) : void +setEmpNum(int num) : void +setEmpSal(double sal) : void +setEmpSal(double sal) : void

Another employee class Suppose that a new employee called serviceRep is hired and that, in addition to employee number and salary, he needs a territory. Suppose that a new employee called serviceRep is hired and that, in addition to employee number and salary, he needs a territory. Rather than creating a whole new class, you can create a new class that inherits the behaviors and attributes of the original employee class Rather than creating a whole new class, you can create a new class that inherits the behaviors and attributes of the original employee class This is reuse at its best This is reuse at its best

Employee -empNum : int -empNum : int -empSal : double -empSal : double +getEmpNum : int +getEmpNum : int +getEmpSal : double +getEmpSal : double +setEmpNum(int num) : void +setEmpNum(int num) : void +setEmpSal(double sal) : void +setEmpSal(double sal) : voidEmployeeWithTerritory -empTerritory : int -empTerritory : int +getEmpTerritory : int +getEmpTerritory : int +setEmpTerritory : void +setEmpTerritory : void

When you use inheritance you: Save time because the Employee fields and methods already exist Save time because the Employee fields and methods already exist Save money because it takes less time to create a class that uses structure in old classes Save money because it takes less time to create a class that uses structure in old classes Reduce errors because the Employee methods already have been used and tested Reduce errors because the Employee methods already have been used and tested Reduce the amount of new learning required to use the new class, because you have used the Employee methods on simpler objects and already understand how they work Reduce the amount of new learning required to use the new class, because you have used the Employee methods on simpler objects and already understand how they work

Base classes Classes from which other classes inherit attributes or methods Classes from which other classes inherit attributes or methods Classes that inherit from base classes are called derived classes Classes that inherit from base classes are called derived classes A base class is also called a superclass A base class is also called a superclass A derived class is also called a subclass A derived class is also called a subclass You can also use the terms parent class and child class You can also use the terms parent class and child class

public class ASubClass extends ASuperClass { public ASubClass() public ASubClass() { System.out.println("In subclass constructor"); System.out.println("In subclass constructor"); }}

public class ASuperClass { public ASuperClass() public ASuperClass() { System.out.println("In superclass constructor"); System.out.println("In superclass constructor"); }}

Extending Classes You use the keyword extends to achieve inheritance in Java You use the keyword extends to achieve inheritance in Java Example: Example: Public class EmployeeWithTerritory extends Employee You used the extends JApplet throughout Chapters 9 and 10— every JApplet that you wrote is a child of the JApplet class You used the extends JApplet throughout Chapters 9 and 10— every JApplet that you wrote is a child of the JApplet class

Object instantiation You instantiate an object with a statement such as You instantiate an object with a statement such as employeeWithTerritory northernRep = new EmployeeWithTerritory(); employeeWithTerritory northernRep = new EmployeeWithTerritory(); Inheritance is a one-way proposition—a child inherits from a parent, not the other way around Inheritance is a one-way proposition—a child inherits from a parent, not the other way around For example an employee object cannot inherit from the employeeWithTerritory subclass—can’t access its methods For example an employee object cannot inherit from the employeeWithTerritory subclass—can’t access its methods

Getting field values from an object You can use any of the next statements to get field values for the northernRep object: You can use any of the next statements to get field values for the northernRep object:northernRep.getEmpNum();northernRep.getEmpSal();northernRep.getEmpTerritory();

After the northernRep object is declared… Any of the following statements are appropriate Any of the following statements are appropriatenorthernRep.setEmpNum(915);northernRep.setEmpSal(210.00);northernRep.setEmpTerritory(5); The northernRep object has access to all the parent Employee class set methods, as well as its own class’s new set method The northernRep object has access to all the parent Employee class set methods, as well as its own class’s new set method

Child classes are more specific An Orthodontist class and Periodontist class are children of the Dentist parent class. An Orthodontist class and Periodontist class are children of the Dentist parent class. The Dentist class does not have a Orthodontist’s applyBraces() method or the Periodontist’s deepClean() method. The Dentist class does not have a Orthodontist’s applyBraces() method or the Periodontist’s deepClean() method. However, Orthodontist objects and Perodontist objects have access to the more general Dentist methods However, Orthodontist objects and Perodontist objects have access to the more general Dentist methods

Instanceof Instances of child classes are also instances of the parent classes of that class Instances of child classes are also instances of the parent classes of that class The following are true: The following are true: If(myOrthodontist instanceof Dentist)… If(myOrthodontist instanceof Orthodontist)…

Overriding Superclass Methods When you extend a superclass, you create a subclass that inherits the superclass attributes and methods When you extend a superclass, you create a subclass that inherits the superclass attributes and methods What do you do if you do not want these attributes and methods? What do you do if you do not want these attributes and methods? You can write your own You can write your own In the musical instruments world a play() method would be very different for a guitar as compared to a drum In the musical instruments world a play() method would be very different for a guitar as compared to a drum This is called polymorphism This is called polymorphism

Polymorphism Literally means ‘many forms’ Literally means ‘many forms’ Consider an employee superclass with a printRateOfPay() method Consider an employee superclass with a printRateOfPay() method For weekly employees the print statement might be For weekly employees the print statement might be System.out.println(“Pay is “ + rateOfPay + “ per week”);System.out.println(“Pay is “ + rateOfPay + “ per week”); For hourly employees the print statement might be For hourly employees the print statement might be System.out.println(“Pay is “ + rateOfPay + “ per hour”);System.out.println(“Pay is “ + rateOfPay + “ per hour”);

What do you do? When you create a method in a child class that has the same name and argument list as a method in its parent class, you override the method in the parent class When you create a method in a child class that has the same name and argument list as a method in its parent class, you override the method in the parent class When you use the method name with a child object, the child’s version of the method is used When you use the method name with a child object, the child’s version of the method is used

As an alternative… You could create and use a method with a different name… You could create and use a method with a different name… But the classes are easier to write and understand if you use one reasonable name for methods that do essentially the same thing. But the classes are easier to write and understand if you use one reasonable name for methods that do essentially the same thing. In the example above, because we are attempting to print the rate of pay for each object, printRateOfPay() is an excellent method name for this function. In the example above, because we are attempting to print the rate of pay for each object, printRateOfPay() is an excellent method name for this function.

Can you think of any other reasons why polymorphism makes sense? When you have to change some aspect of behavior that is common to all of the classes and that piece of behavior is inherited, then you have to change it only in one place—not ten places When you have to change some aspect of behavior that is common to all of the classes and that piece of behavior is inherited, then you have to change it only in one place—not ten places

Understanding how Constructors are called During Inheritance Consider the following: Consider the following: SomeClass anObject = new SomeClass(); Here you are instantiating an object of a subclass by invoking the SomeClass() constructor Here you are instantiating an object of a subclass by invoking the SomeClass() constructor You are actually calling at least two constructors: the constructor for the base class and the constructor for the extended, derived class. You are actually calling at least two constructors: the constructor for the base class and the constructor for the extended, derived class. When a subclass constructor executes, the superclass constructor must execute first and then the subclass constructor When a subclass constructor executes, the superclass constructor must execute first and then the subclass constructor

More… Often the execution of the superclass constructor is transparent—nothing call attention to the fact that the superclass constructor is executing. Often the execution of the superclass constructor is transparent—nothing call attention to the fact that the superclass constructor is executing.

Question… Suppose that HourlyEmployee is a subclass of Employee. Suppose that HourlyEmployee is a subclass of Employee. When you create an object of HourlyEmployee called clerk When you create an object of HourlyEmployee called clerk What happens in terms of the constructors involved??? What happens in terms of the constructors involved???

public class ASuperClass { public ASuperClass() { System.out.println(“In superclass constructor”); }} public class ASubClass extends ASuperClass { public ASubClass() { System.out.println(“In subclass constructor”); }} public class DemoConstructors { public static void main(String[] args) { aSubClass child = new ASubClass90; }}

The above produces the following output at the Command Prompt C:\Java\java DemoConstructors In superclass constructor In subclass constructor

Using Superclass Constructors that Require Arguments When you create a class and do not provide a constructor, Java automatically supplies you with a default constructor—one that never requires arguments When you create a class and do not provide a constructor, Java automatically supplies you with a default constructor—one that never requires arguments When you write your own constructor, you replace the automatically supplied version When you write your own constructor, you replace the automatically supplied version

More on constructors… When all superclass constructors have constructors that require arguments, you must make sure the subclass constructors provide those arguments When all superclass constructors have constructors that require arguments, you must make sure the subclass constructors provide those arguments In this case there is no default superclass constructor without args In this case there is no default superclass constructor without args

More on constructors Your subclass constructors can contain any number of statements, but the first statement within each subclass constructor must call the superclass constructor Your subclass constructors can contain any number of statements, but the first statement within each subclass constructor must call the superclass constructor The format for the statement that calls a superclass constructor is The format for the statement that calls a superclass constructor is super(list of arguments); super(list of arguments);

Accessing Superclass Methods When two methods use the same name in both a superclass and a subclass, the sublcass method overrides the supperclass method. When two methods use the same name in both a superclass and a subclass, the sublcass method overrides the supperclass method. When you want the superclass method to be used, you use the keyword super to access the superclass method When you want the superclass method to be used, you use the keyword super to access the superclass method

public class Customer { private int idNumber; private int idNumber; private double balanceOwed; private double balanceOwed; public Customer(int id, double bal) public Customer(int id, double bal) { idNumber = id; idNumber = id; balanceOwed = bal; balanceOwed = bal; } public void display() public void display() { System.out.println("Customer #" + idNumber + System.out.println("Customer #" + idNumber + " Balance $" + balanceOwed); " Balance $" + balanceOwed); }}

public class PreferredCustomer extends Customer { double discountRate; double discountRate; public PreferredCustomer(int id, double bal, double rate) public PreferredCustomer(int id, double bal, double rate) { super(id, bal); super(id, bal); discountRate = rate; discountRate = rate; } public void display() public void display() { super.display(); super.display(); System.out.println("Discount rate is " + discountRate); System.out.println("Discount rate is " + discountRate); }}

public class TestCustomers { public static void main(String[] args) public static void main(String[] args) { Customer oneCust = new Customer(124, ); Customer oneCust = new Customer(124, ); PreferredCustomer onePCust = new PreferredCustomer onePCust = new PreferredCustomer(125, , 0.15); PreferredCustomer(125, , 0.15); oneCust.display(); oneCust.display(); onePCust.display(); onePCust.display(); }}

Command Prompt C:\Java>Java TestCustomers C:\Java>Java TestCustomers Customer #124 Balance $ Customer #124 Balance $ Chstomer #125 Balance $ Chstomer #125 Balance $ Discount rate is 0.15 Discount rate is 0.15 C:\Java> C:\Java>

public class DemoConstructors { public static void main(String[] args) public static void main(String[] args) { ASubClass child = new ASubClass(); ASubClass child = new ASubClass(); }}

Learning about Information Hiding Information hiding is a way to disallow certain attributes and methods to be accessible within other classes Information hiding is a way to disallow certain attributes and methods to be accessible within other classes We use the keyword private to make an attribute or method local to the class and not accessible elsewhere We use the keyword private to make an attribute or method local to the class and not accessible elsewhere

public class Student { private int idNum; private int idNum; private double gpa; private double gpa; public int getIdNum; public int getIdNum; { return idNum; return idNum; } public double getGpa() public double getGpa() { return gpa; return gpa; } public void setIdNum(int num) public void setIdNum(int num) { idNum = num; idNum = num; } public void setGpa(double gradePoint) public void setGpa(double gradePoint) { gpa = gradePoint; gpa = gradePoint; }}

Why won’t the following code work?? Suppose you write a main() method in another class that does the following… Suppose you write a main() method in another class that does the following… Student someStudent = new Student(); someStudent.idNum = 812; Only methods contained within the student class are allowed to alter Student data: Only methods contained within the student class are allowed to alter Student data:someStudent.setIdNum(812);

Remember… The methods in a subclass can use all the fields (attributes, data) in an inherited superclass as well as its methods, except…. The methods in a subclass can use all the fields (attributes, data) in an inherited superclass as well as its methods, except…. Those declared as…. Those declared as….

This is called ….

Are there other access modifiers?? Yes, Virginia, there are… Yes, Virginia, there are… Suppose that you want data to be accessible to the class it was defined in as well as subclasses that extend that class, but not in any other classes—that is you don’t want the data to be public Suppose that you want data to be accessible to the class it was defined in as well as subclasses that extend that class, but not in any other classes—that is you don’t want the data to be public Then, you use the keyword protected Then, you use the keyword protected

Using Methods you cannot Override The three types of methods that you cannot override in a subclass are: The three types of methods that you cannot override in a subclass are: static methods static methods final methods final methods Methods within final classes Methods within final classes

A Subclass Cannot Override static Methods in its Superclass A subclass cannot override methods that are declared static in the superclass. A subclass cannot override methods that are declared static in the superclass. Not even with the keyword super Not even with the keyword super See code below in which ProfessionalBaseballPlayer extends BaseballPlayer See code below in which ProfessionalBaseballPlayer extends BaseballPlayer

public class BaseballPlayer { private int jerseyNumber; private int jerseyNumber; private double battingAvg; private double battingAvg; public static void printOrigins() public static void printOrigins() { System.out.println("Abner Doubleday is often " + System.out.println("Abner Doubleday is often " + "credited with inventing baseball"); "credited with inventing baseball"); }}

public class ProfessionalBaseballPlayer extends BaseballPlayer { double salary; double salary; public void printOrigins() public void printOrigins() { BaseballPlayer.printOrigins(); BaseballPlayer.printOrigins(); System.out.println("The first professional " + System.out.println("The first professional " + "major league baseball game was played in 1871"); "major league baseball game was played in 1871"); }}

In the above two frames of code.. Java does not allow the printOrigins() in the subclass ProfessionalBaseballPlayer to override the static method printOrigins() in the superclass BaseballPlayer Java does not allow the printOrigins() in the subclass ProfessionalBaseballPlayer to override the static method printOrigins() in the superclass BaseballPlayer This doesn’t work even if you declare the method printOrigins() in the subclass ProfessionalBaseballPlayer to be static, as follows: This doesn’t work even if you declare the method printOrigins() in the subclass ProfessionalBaseballPlayer to be static, as follows:

public class ProfessionalBaseballPlayer extends BaseballPlayer { double salary; double salary; public static void printOrigins() public static void printOrigins() { super.printOrigins(); super.printOrigins(); System.out.println("The first professional " + System.out.println("The first professional " + "major league baseball game was played in 1871"); "major league baseball game was played in 1871"); }}

However, the following code will work: However, the following code will work:

public class ProfessionalBaseballPlayer extends BaseballPlayer { double salary; double salary; public static void printOrigins() public static void printOrigins() { BaseballPlayer.printOrigins(); BaseballPlayer.printOrigins(); System.out.println("The first professional " + System.out.println("The first professional " + "major league baseball game was played in 1871"); "major league baseball game was played in 1871"); }}

When used with the following class: Public class TestProPlayer { public static void main(String[] args) public static void main(String[] args) { professionalBaseballPlayer aYankee = new ProfessionalBaseballPlayer(); professionalBaseballPlayer aYankee = new ProfessionalBaseballPlayer(); aYankee.printOrigins(); aYankee.printOrigins(); }}

The following output will be produced C:\Java>Java TestProPlayer C:\Java>Java TestProPlayer Abner Doubleday is often credited with inventing baseball Abner Doubleday is often credited with inventing baseball The first professional major league baseball game was played in 1871 The first professional major league baseball game was played in 1871

A Subclass Cannot Override final Methods in its Superclass A subclass cannot override methods that are declared final in the superclass. A subclass cannot override methods that are declared final in the superclass. Consider the classes BasketballPlayer and ProfessionalBasketballPlayer below Consider the classes BasketballPlayer and ProfessionalBasketballPlayer below These will generate an error at compile time These will generate an error at compile time

public class BasketballPlayer { private int jerseyNumber; private int jerseyNumber; public final void printMessage() public final void printMessage() { System.out.println("Michael Jordan is the " + System.out.println("Michael Jordan is the " + "greatest basketball player - and that is final"); "greatest basketball player - and that is final"); }}

public class ProfessionalBasketballPlayer extends BasketballPlayer { double salary; double salary; public void printMessage() public void printMessage() { System.out.println("I have nothing to say"); System.out.println("I have nothing to say"); }}

Public void display(BasketballPlayer bbplayer) { bbplayer.printMessage(); bbplayer.printMessage();} The above will cause the code created for printMessage() to be inserted inline and the practice is called inlining.

A Subclass Cannot Override Methods in a final Superclass You can also declare a class to be final You can also declare a class to be final Then all of its methods will be final as well, regardless of what access modifiers precede the method name in the melthod header Then all of its methods will be final as well, regardless of what access modifiers precede the method name in the melthod header

public final class HideAndGoSeekPlayer { private int count; private int count; public void printRules() public void printRules() { System.out.println("You have to count to " + count + System.out.println("You have to count to " + count + " before you start looking for hiders"); " before you start looking for hiders"); }

public final class ProfessionalHideAndGoSeekPlayer extends HideAndGoSeekPlayer extends HideAndGoSeekPlayer{ private double salary; private double salary;}

The above two frames of code will generate a compiler error when you try to compile the ProfessionalHideAndGoSeekPlayer class. The above two frames of code will generate a compiler error when you try to compile the ProfessionalHideAndGoSeekPlayer class.

The end

Creating a Subclass Method that Overrides a Superclass Method

Understanding the role of Constructors in Inheritance

Understanding Inheritance when the Superclass Requires Constructor Arguments

Accessing an Overridden Superclass Method from within a Subclass

Understanding the protected Access Modifier