C# Tutorial 22 – Class Inheritance

C# Tutorial 22 - Class Inheritance

Here we learn how to inherit from a Class and learn the difference between a “has a” relationship and an “is a” relationship. Visit my website at thebosscode…
Video Tutorial Rating: 4 / 5

Don’t forget to check out our other video tutorials or share this video with a friend.

1 Star2 Stars3 Stars4 Stars5 Stars 0 votes
Loading... 4,083 views





10 responses to “C# Tutorial 22 – Class Inheritance”

  1. Drew Kennedy says:

    this is an old video and meant for new programmers, but you still should be
    using best practices to teach good habits early on (i’m being picky).

    instead of making global variables that have their own unique name, which
    is a waste of a variable name, you should make all relevant variable names
    the same, and use the “this” keyword to point to the global variable(s).
    example:

    class Car {
    private int tankSize¹;
    private int horsePower¹;

    public Car(int tankSize², int horsePower²) {
    this.tankSize¹ = tanksize²;
    this.horsePower¹ = horsePower²;
    }
    }

    Note that the degree numbers are just used to show how the variables are
    being used. Also, you don’t need to give the variables a value in the base
    class. They’ll be initialized and/or overridden by the constructor anyway,
    so it’s a waste of memory.

    Note: I’m not trying to rip your video apart, but rather help newbies out
    for best practices right away. Happy coding! :)

  2. Pirvu Mihai says:

    First year in College at CS, but I do OOP in second year. I took an
    optional paid course for C# which is ‘taught’ by an older student (year 4
    or smth) therefore inexperienced.

  3. Pirvu Mihai says:

    Well, I’m pretty new to C# myself (about 2-3 months, at a facultative
    course) and I feel that they’ve focused on totally wrong things so far and
    that’s why I searched for an online tutorial. Thanks you for doing this. In
    about 3 weeks I’m gonna have a practical exam and I feel really afraid of
    it to be honest. I have close to no experience to OOP. I’ve done C/C++
    mostly so far (no OOP), so this is a totally new thing for me.

  4. TheBossCoder says:

    Thanks for pointing all of these things out to me, though. You’ve been
    giving me a lot of feedback in just a few days!

  5. TheBossCoder says:

    Yes, that’s correct. If I said something different, then good for you for
    pointing it out! When I recorded this, I hadn’t coded in Java for quite
    some time, so I may have forgotten the discrepancies between Java and C#.

  6. tylerpnn says:

    Java can only inherit from one class at a time. That is, a class in java
    can only extend one other class, but it can implement multiple interfaces
    which is very different. I don’t know too much about c++, but I believe it
    does allow multiple-inheritance.

  7. TheBossCoder says:

    I know, and that would have made the implementation a lot simpler; however,
    since this is a tutorial series, I assume no prior knowledge of the
    programming language and I have yet to discuss the “this” keyword yet, so
    using it would/may have caused some confusion.

  8. TheBossCoder says:

    So, they’ve been teaching you C# for about 2-3 months and they have yet to
    touch on OOP? Sounds to me like someone isn’t doing their job correctly.

  9. Pirvu Mihai says:

    Here you could’ve used ‘this’ word at 7:30 for even better usage. instead
    of private int tankSizeActual, you could’ve named it tankSize and used in
    the Car constructor: this.tankSize=tankSize;

  10. TheBossCoder says:

    Well, now that I think about it, my Computer Science course in high school
    didn’t get to OOP for a few months, but any tests we had did not test us
    over OOP. If the teacher hasn’t taught you OOP, they should not test you
    over it.

Leave a Reply

Your email address will not be published. Required fields are marked *