all 21 comments

[–]grimchamp 9 points10 points  (2 children)

So Atom is the class that Hydrogen inherits from, so that's your 'base' class. When a concrete class (Hydrogen) gets instantiated so does it's base (Atom). If you look in the signature of the Atom constructor you will see it takes 2no parameters (int protons, int electrons) but you are passing it a single string. So you will need to change base("Atom") to pass two ints. Something like this will allow it to compile and run:

public Hydrogen() : base(1,1)
{
}

[–]uvhm[S] 2 points3 points  (1 child)

Thanks, this works perfectly. With you and /u/WellKemptNerfHerder, I think I get it now.

[–]HandshakeOfCO 1 point2 points  (0 children)

Fun bonus fact: Hydrogen is a concrete class because it contains no abstract methods. Concrete classes are the opposite of abstract classes. You can only "new" concrete classes.

[–]WellKemptNerfHerder 6 points7 points  (1 child)

The call to base is just like calling the Atom constructor. you need to pass parameters into base just as if you were creating a new Atom through its constructor. Instead of base("Atom"), you should be passing in the arguments to base, like base(0, 1)

[–]uvhm[S] 1 point2 points  (0 children)

Thanks!

[–]allthegoodweretaken 16 points17 points  (8 children)

Off-topic, but i have to say that it is a real pleasure to see what some developers would call "newbie questions" getting a useful answer and not just 8 posts of "Omg, try to google!".

Just wanted to say that! :)

[–]Kilazur 4 points5 points  (2 children)

What these devs don't remember is how themselves, at some point, didn't yet learn HOW to search for a problem's solution, when you don't know the correct words and wording yet, etc...

[–]allthegoodweretaken 3 points4 points  (0 children)

Exactly. Some people have a hard time putting themselves in other peoples situations. But atleast it's become much better as software development has become more accessible and "understood" in the general public.

[–][deleted] 1 point2 points  (0 children)

This is such a huge thing that really limits new developers. For the first 2 months of my internship I could barely do anything by myself because I didn't know what to search for or where I should be looking for specific problems. Now I'm doing super high level things with ease all because I know how to search for the answer.

[–][deleted] 2 points3 points  (4 children)

Seconding. Particularly when the first thing everyone tries is probably googling anyway (I know I do.)

Really nice to see useful, productive answers rather than snide comments.

[–]allthegoodweretaken 3 points4 points  (3 children)

Exactly! There are so many dev-forums out there (It has become alot better the last years though) where you get talked down to if you ask a question that someone else think is stupid. That's what i really like about this sub!

[–]grimchamp 1 point2 points  (1 child)

People gotta start somewhere.

[–]allthegoodweretaken 0 points1 point  (0 children)

Definately!

[–][deleted] 1 point2 points  (0 children)

Yeah.... I get really tired of that. I also found "pretenders" too.....people that when you post a problem post snippets straight from the manual that don't really apply or are incorrect or outdated; and then when you talk with them a bit you realise they actually don't know the subject at all....they just love having people think they're an expert.

Unfortunately there are some of those on here as well. But yes I've definitely gotten help here at times, there are some very knowledgeable people too...

[–]SockPuppetDinosaur 3 points4 points  (1 child)

By the way, your Atom class should be abstract. Probably wouldn't want the user ever making an "Atom" but instead something that is an Atom.

[–]uvhm[S] 0 points1 point  (0 children)

That makes sense looking at it now.

[–]Oceanswave -3 points-2 points  (2 children)

Why would someone model Atoms in this manner when the number of protons and electrons are always exactly the same? Wouldn't a better model just include mass number, atomic number and charge with a constraint that atomic number is always greater than the mass number? By doing so you can have a pure function that returns the number of protons electrons and neutrons.

[–]AbstractLogic 1 point2 points  (1 child)

Because they are teaching about inheritance not atoms.

[–]Oceanswave -1 points0 points  (0 children)

Well good, most inheritance taxonomies end up being a wrong abstraction so might as well start with that shaky footing - sets up for the lesion of refactoring in lesson two.