Consider the PlayingCard, Rank and Suit classes.            a)Which two classes are instance variables in the third class?            b)Are instance variables an is-a or has-a relationship?

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question
  1. Consider the PlayingCard, Rank and Suit classes.

           a)Which two classes are instance variables in the third class?

           b)Are instance variables an is-a or has-a relationship?

"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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,