Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite0
Valentine, Holiday, and Birthday inherit from the class Card. In order for the following code to be correct, what type must the
Valentine, Holiday, and Birthday inherit from the class Card. In order for the following code to be correct, what type must the reference variable card be?
6 Réponses
+ 2
It would be of type Card (coming from a Java perspective anyway)
You can have
class Card {...}
and then the three other classes
class Valentine extends Card {...}
class Holiday extends Card {...}
class Birthday extends Card {...}
So if you then needed to refer to a Card object that isn’t three of the above, you would do
Card c = new Card();
(assuming the classes have constructors in place)
Your other three types can be declared as
Valentine v = new Valentine();
Holiday h = new Holiday();
Birthday b = new Birthday();
and v, h and b can use methods from the Card class
+ 2
the answer is "Card".
+ 1
card
0
card
0
The correct answer is: card
0
the answer is "Card".