I'd think selfishness & generosity can be learned but that there's a genetic component. I was always generous with my toys and that was from even before I learned about sex, so much so that even when I was a little kid I remember myself feeling badly for my friends whose parents didn't throw them birthday parties even back in the single digits. It affected me so much that I'd be sad for them during my own party, knowing they didn't get one of their own. So I always looked out for them that they had a good time. Later in life as an adult when I learned of sex I did the same thing. Always made sure everyone had a good time.
And then as a grown up I watched from when they were kids my niece and nephews and there was a big difference from when they were also in single digit ages. My niece, though a good kid, was always in it for herself, whether playing games or whatever. Strikingly different was my nephew who is like me in so many ways. This kid was always a generous soul. From when he was very little he exhibited empathy and caring for others in great quantity.
Just a quick example. At lunch one time when he was a little kid, he wanted to show me "a magic trick" or illusion whatever it was with a bill. So I gave him a 10 spot I had in my pocket. He did his little trick. It was cute. And I told him to keep the bill as payment for his performance. He refused. I insisted. Thought I won that one. On our way to the car, he takes the bill and quickly--so this kid put thought into that--he puts it back into my pocket as we're walking. Refused to take it again when I tried to give it back.
He'd later join the civil air patrol in high school or junior high, whenever that was, and now he's studying to be a paramedic in college so he can help people. This kid was born that way. Outside of learning to defend himself and not letting others take advantage of him, life will never be able to teach him how to be selfish.