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

Show parent comments

1

u/[deleted] Oct 15 '16

Funny, I remember having similar feelings when I was in school. I've had two jobs since graduating doing software development and I was surprised how much carry over school had. I felt the same way like how you said "fake problems", but it does prepare you for the real world.

The biggest difference is that, unless you end up working for a startup or a small company, you will probably end up joining a project that is mostly complete and has a gigantic codebase. You end up working on a much more "macro" level with the code since a lot of the underlying systems are already completed. Again this is not every job, just probably what your average programmer is doing (in java of course).