Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Here's a few examples of using Inheritance across several different languages, so you can read and recognize it in code when you see it. And don't worry about memorizing syntax here, we're just trying to get an overview. If I want to create a new class called Album that inherits from a Product class, this would be the way that I would do it in Java. Just simply use the extends word, and then the name of the class that I want to inherit from. In C# we'd use a colon. This is a very common way to denote Inheritance.
Album inherits from Product. In VB.NET we actually use the word Inherits. Ruby is a little different, it uses the Less Than sign to say that Album inherits from Product. C++ uses the colon as does Objective-C. So taking this first basic idea of Inheritance between languages really is a very minor syntax change. Although, however, the details of overriding, that's allowing a new class to replace the implementation of the method in superclass are a little too specific to the language to be useful here.
As some languages require keywords, others don't. Some languages require keywords in both the superclass and subclass and so on, so for overriding details, I'm going to refer you to your chosen language. One common need is for code in the subclass, the new child class, to call a method that was originally defined in the superclass, in the Parent class. And there's the question: How would we write a line of code in the child to call something in the parent? Well, the word that you'll most often see is super.
So in Java we would say super-dot and then the name of the method that was written in the superclass. .NET languages tend to use the word base instead of super, so they use base class and derived class rather than superclass and subclass. But the thought behind it is identical. So in C# we use the word base, in VB.NET it's actually the word MyBase. Ruby uses the word super, as does Objective-C. So that is the most common way of doing it. C++ is a little different, because C++ allows for multiple inheritance.
We could be theoretically inheriting from multiple classes. So we can just say super and know that we'll automatically go to the one superclass. So with C++ you actually have to use the official name of whatever class you're talking about. But again, here the syntax differences are the least things to be concerned about. I'm much more interested in your realizing just how well the same concepts work across multiple languages. However, Inheritance isn't the only kind of relationship we can have between classes, and next we're going to see another one called Composition.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101728 Viewers
61 Video lessons · 88489 Viewers
71 Video lessons · 72307 Viewers
56 Video lessons · 104022 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.