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

329

u/Noclue55 Oct 15 '16

As someone who doesn't get the joke, but understanding that you are a very knowledgeable person I have this to say.

96

u/ExistentialEnso Oct 15 '16

The reality is it barely shows any knowledge at all. This is third week of CS101-level knowledge. It's about as basic as it gets with coding jokes.

3

u/Antonin__Dvorak Oct 15 '16

What kind of CS program starts with Java?! That's like an intro mechanics course starting out with Ferrari engines.

14

u/ExistentialEnso Oct 15 '16

It's extremely common these days. Most CS programs start people off with either Java or Python.

I also disagree with that analogy. I guess you mean in terms of complexity, which I can kind of see, but if anything, Java is more like a minivan. It's inefficient and bulky, but it has a lot of utilitarian value and is easy to use, so a lot of people fall back on it anyway.

3

u/Antonin__Dvorak Oct 15 '16

I see what you mean. The analogy was meant to demonstrate how complex Java is - it's really easy for a beginner to get lost in the nitty gritty of the language constructs, and miss out on important CS concepts as a result.

Python makes more sense, but ideally it would be something even simpler - a functional language like Scheme, for instance.

6

u/ExistentialEnso Oct 15 '16

Gotcha, I can see how the analogy makes sense from that angle, you're just going to always get a lot of funny looks if you compare Java to a sports car.

Starting with functional programming is one of those things that makes a lot of sense from an academic perspective but almost no sense from a practical one. If the goal is to prepare someone as much as possible for the software industry without requiring further degrees, it's just a waste of time. If someone is going to go on to get an MS or PhD, sure.

But the industry is a lot different than academia. For instance, the vast majority of coders are never going to have to manually write a sort function or calculate the Big-O notation of something outside of a job interview. Most of the best coders I've worked with were not CS majors, actually, many having no academic programming experience at all.

The single biggest factor actually under someone's control (i.e. not just raw talent) that will determine how good of a coder someone will be is simply how much hands on experience they have. You just need to code a lot of things in a lot of different languages and frameworks, so you have the flexibility to adapt to new technologies. This is one of the most rapidly changing industries, and you have to be ready to keep up.

→ More replies (0)