+ 1

Ruby - Class inheritance - Why is output "PUBGM"?

class Game @@play = "Fortnite" def self.play @@play end end class Mobile_Game < Game @@play = "PUBGM" end puts Game.play

14th Oct 2019, 11:47 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 Answers
+ 1
Well, but why the subclass one "wins" over the class one?
14th Oct 2019, 12:19 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
0
class variable is shared between class and its subclass
14th Oct 2019, 12:18 PM
Taste
Taste - avatar
0
by testing it, it seems so. i'm not playing much with ruby
14th Oct 2019, 12:20 PM
Taste
Taste - avatar