Class Card
Class Card
(Fig. E.8) contains two String
instance variables—face
and suit
—that are used to store references to the face name and suit name for a specific Card
. The constructor for the class (lines 10–14) receives two String
s that it uses to initialize face
and suit
. Method toString
(lines 17–20) creates a String
consisting of the face
of the card
, the String " of "
and the suit
of the card. Card
’s toString
method can be invoked explicitly to obtain a string representation of a Card
object (e.g., "Ace of Spades"
). The toString
method of an object is called implicitly when the object is used where a String
is expected (e.g., when printf
outputs the object as a String
using the %s
format specifier or when the object is concatenated to ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.