Give a complete definition of a class called TitledPerson, which youderive from the class Person in Listing 8.1. The class TitledPerson hasone additional String instance variable for a title, such as Ms., Mr.,or The Honorable. The class TitledPerson has two constructors: adefault constructor and one that sets both the name and the title. It hasa writeOutput method, a reset method, an equals method, an accessormethod getTitle that returns the title, and a mutator method setTitlethat changes the person’s title. For two titled people to be equal, theymust have the same name and the same title. You may want to use theclass Student in Listing 8.2 as a model.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Give a complete definition of a class called TitledPerson, which you
derive from the class Person in Listing 8.1. The class TitledPerson has
one additional String instance variable for a title, such as Ms., Mr.,
or The Honorable. The class TitledPerson has two constructors: a
default constructor and one that sets both the name and the title. It has
a writeOutput method, a reset method, an equals method, an accessor
method getTitle that returns the title, and a mutator method setTitle
that changes the person’s title. For two titled people to be equal, they
must have the same name and the same title. You may want to use the
class Student in Listing 8.2 as a model.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images