2. Consider the BlackJackCard and PlayingCard classes.               a)Do these two classes have an is-a or has-a relationship?              b)Which class is the more general class?              c)Which class is the more specialized class?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question

2. Consider the BlackJackCard and PlayingCard classes. 

             a)Do these two classes have an is-a or has-a relationship?

             b)Which class is the more general class?

             c)Which class is the more specialized class? 

             d)Would the four methods from the general class be appropriate in the specialized class? Explain your answer.

             e)Give one example of a method that might appear in the specialized class but not the more general class.



"Is-a" versus "Has-a"
A large program will often be built out of multiple classes. Often, these classes will have a "has a"
relationship. For example, a game program might include three classes: PlayingCard, Suit, and Rank. A
PlayingCard object has a Suit and has a Rank, which are handled in a Java program as instance
variables.
PlayingCard
- cardRank: Rank
cardSuit: Suit
+ setRank (Rank rank): void
+ setSuit (Suit suit): void
+ getRank (): Rank
+ getSuit (): Suit
Class Name
Data Fields
Methods
Less often, you might have two classes which have an “is a” relationship, where one class is a more
general class, while the second class is a more specialized version of the original class. A blackjack
program might have a BlackJackCard class which is a PlayingCard. Notice the relationship is not
symmetrical: every BlackJackCard is a PlayingCard, but not every PlayingCard is a BlackJackCard.
Transcribed Image Text:"Is-a" versus "Has-a" A large program will often be built out of multiple classes. Often, these classes will have a "has a" relationship. For example, a game program might include three classes: PlayingCard, Suit, and Rank. A PlayingCard object has a Suit and has a Rank, which are handled in a Java program as instance variables. PlayingCard - cardRank: Rank cardSuit: Suit + setRank (Rank rank): void + setSuit (Suit suit): void + getRank (): Rank + getSuit (): Suit Class Name Data Fields Methods Less often, you might have two classes which have an “is a” relationship, where one class is a more general class, while the second class is a more specialized version of the original class. A blackjack program might have a BlackJackCard class which is a PlayingCard. Notice the relationship is not symmetrical: every BlackJackCard is a PlayingCard, but not every PlayingCard is a BlackJackCard.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,