Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose you are tasked with writing classes and/or interfaces in Java for the following: The data type Magical is for things that say a magical

Suppose you are tasked with writing classes and/or interfaces in Java for the following:
The data type Magical is for things that say a magical phrase. Its only method is
magicPhrase(), which returns the magical phrase as a String. Magical does not supply
an implementation of this method. Instead, this method is to be implemented by sub-
types of Magical.
Data type Princess is both a sub-type of class Person (from question 1) and a sub-type
of Magical.
A Princess has a hair length (stored in a data field of type int called hairLength).
The class user can view the hairLength of a Princess (using a get method), but they
cannot modify the hairLength.
The constructor of Princess is accessible by the class user. Its parameters are the
name, age, and hair length (in this order). Call these parameters name, age and hairLen
respectively. It takes these parameters and initializes its corresponding data fields to these values
queston: Method favoriteInt() is overridden in Princess to do the following: call Persons
implementation of favoriteInt(), add hairLength to this, and return this resulting
sum.
Method magicPhrase() is overridden in Princess to return
favoriteInt() + " sparkles for everyone!"
(a) Should Magical be an abstract class, a non-abstract class, or an interface?
Explain your reasoning.
(b) What members (data fields and methods) does Princess inherit from class
Person?
(c) (4 points) Should the constructor for Princess have an explicit call to the constructor
c) Should the constructor for Princess have an explicit call to the constructor
of class Person? If so, write the line of code for this call. If not, explain why not.
(d) Write Java code for the data type Princess as described above.
all of these especially the last one

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Appreciate common obstacles to performance appraisals

Answered: 1 week ago

Question

LO2 Explain the nature of the psychological contract.

Answered: 1 week ago