r/learndota2 • • Oct 14 '16

All Time Top Post [Java] How does inheritance really work?

I have a following class:

public class Parent {
    private int number;

   // more stuff
}

And another, which inherits from Parent:

public class Child extends Parent {
    public void setNumber(int newNum){
        this.number = newNum;
    }
}

I always thought Child was a copy of Parent, but you could add stuff to it (and possibly change something). So I would expect it already has the 'number' attribute. However this will never compile as there isn't anything named like that. Why?

EDIT: I am sorry, guys. I thought this was /r/learnprogramming. I don't play dota and I am not even subscribed so this is a mystery to me.

2.8k Upvotes

245 comments sorted by

View all comments

236

u/TheDrGoo Old School Oct 15 '16

10/10 keeping it despite it being reported quite a few times.

72

u/VirulentWalrus M - Through anger, lies failure. Oct 15 '16 edited Jan 20 '26

unwritten seemly snails oatmeal grab bear axiomatic versed engine kiss

This post was mass deleted and anonymized with Redact

57

u/Cuddles_theBear Oct 15 '16

It seems like you are subscribed to /r/learnjava by mistake. Did you mean to subscribe to /r/AlcoholismIsTheOnlyThingThatMakesMyLifeWorthwhile ?

28

u/SerpentineLogic 💖 AUTZ 💖 Oct 15 '16

My favourite beer is made in an AbstractFactory.

6

u/[deleted] Oct 15 '16

wtf is up with your ember?

13

u/VirulentWalrus M - Through anger, lies failure. Oct 15 '16 edited Jan 20 '26

history jar mysterious dazzling elderly tender aromatic chief physical water

This post was mass deleted and anonymized with Redact

1

u/YaqP Nov 04 '16

I always thought it was a Dark Seer, but TIL.

10

u/Rammite Shitty Support Main Oct 15 '16

He likes purple.

4

u/Sir_Rebral Oct 15 '16

Maledict?

2

u/VirulentWalrus M - Through anger, lies failure. Oct 16 '16

That spell triggers me heavily.

2

u/UlyssesSKrunk Oct 15 '16

Well duh, you're here and this is /r/learnjava.