Class Inheritance

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.55
List Price:  €119.77
You save:  €34.22
£74.16
List Price:  £103.84
You save:  £29.67
CA$137.94
List Price:  CA$193.12
You save:  CA$55.18
A$152.78
List Price:  A$213.90
You save:  A$61.12
S$128.67
List Price:  S$180.14
You save:  S$51.47
HK$780.19
List Price:  HK$1,092.31
You save:  HK$312.11
CHF 80.30
List Price:  CHF 112.42
You save:  CHF 32.12
NOK kr1,004.34
List Price:  NOK kr1,406.11
You save:  NOK kr401.77
DKK kr638.63
List Price:  DKK kr894.11
You save:  DKK kr255.47
NZ$170.14
List Price:  NZ$238.20
You save:  NZ$68.06
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,172.20
List Price:  ৳17,041.56
You save:  ৳4,869.36
₹8,825.07
List Price:  ₹12,355.46
You save:  ₹3,530.38
RM422.33
List Price:  RM591.28
You save:  RM168.95
₦152,828.71
List Price:  ₦213,966.31
You save:  ₦61,137.60
₨28,385.35
List Price:  ₨39,740.62
You save:  ₨11,355.27
฿3,218.97
List Price:  ฿4,506.69
You save:  ฿1,287.72
₺4,125.04
List Price:  ₺5,775.22
You save:  ₺1,650.18
B$544.72
List Price:  B$762.63
You save:  B$217.91
R1,768.44
List Price:  R2,475.88
You save:  R707.44
Лв167.48
List Price:  Лв234.49
You save:  Лв67
₩139,005.46
List Price:  ₩194,613.20
You save:  ₩55,607.74
₪333.96
List Price:  ₪467.56
You save:  ₪133.59
₱5,689.88
List Price:  ₱7,966.06
You save:  ₱2,276.18
¥14,815.95
List Price:  ¥20,742.93
You save:  ¥5,926.97
MX$1,867.49
List Price:  MX$2,614.56
You save:  MX$747.07
QR364.04
List Price:  QR509.67
You save:  QR145.63
P1,439.16
List Price:  P2,014.89
You save:  P575.72
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£4,854.53
List Price:  E£6,796.54
You save:  E£1,942
ብር14,306.63
List Price:  ብር20,029.86
You save:  ብር5,723.22
Kz91,186.39
List Price:  Kz127,664.59
You save:  Kz36,478.20
CLP$97,214.27
List Price:  CLP$136,103.87
You save:  CLP$38,889.60
CN¥713
List Price:  CN¥998.24
You save:  CN¥285.23
RD$6,340.36
List Price:  RD$8,876.76
You save:  RD$2,536.40
DA12,985.04
List Price:  DA18,179.58
You save:  DA5,194.53
FJ$225.61
List Price:  FJ$315.87
You save:  FJ$90.25
Q767.35
List Price:  Q1,074.33
You save:  Q306.97
GY$20,923.93
List Price:  GY$29,294.34
You save:  GY$8,370.41
ISK kr12,250.77
List Price:  ISK kr17,151.57
You save:  ISK kr4,900.80
DH907.55
List Price:  DH1,270.61
You save:  DH363.06
L1,676.34
List Price:  L2,346.95
You save:  L670.60
ден5,281.40
List Price:  ден7,394.17
You save:  ден2,112.77
MOP$803.54
List Price:  MOP$1,124.98
You save:  MOP$321.44
N$1,773.82
List Price:  N$2,483.42
You save:  N$709.60
C$3,680.31
List Price:  C$5,152.59
You save:  C$1,472.27
रु14,096.01
List Price:  रु19,734.98
You save:  रु5,638.96
S/352.21
List Price:  S/493.11
You save:  S/140.90
K423.82
List Price:  K593.36
You save:  K169.54
SAR375.17
List Price:  SAR525.26
You save:  SAR150.08
ZK2,380.02
List Price:  ZK3,332.12
You save:  ZK952.10
L434.52
List Price:  L608.35
You save:  L173.82
Kč2,090.29
List Price:  Kč2,926.49
You save:  Kč836.19
Ft33,616.37
List Price:  Ft47,064.26
You save:  Ft13,447.89
SEK kr940.94
List Price:  SEK kr1,317.36
You save:  SEK kr376.41
ARS$136,236.96
List Price:  ARS$190,737.20
You save:  ARS$54,500.23
Bs691.36
List Price:  Bs967.94
You save:  Bs276.57
COP$399,414.69
List Price:  COP$559,196.55
You save:  COP$159,781.85
₡50,561.46
List Price:  ₡70,788.07
You save:  ₡20,226.60
L2,620.33
List Price:  L3,668.57
You save:  L1,048.24
₲720,925.20
List Price:  ₲1,009,324.12
You save:  ₲288,398.92
$U4,006.62
List Price:  $U5,609.43
You save:  $U1,602.81
zł363.92
List Price:  zł509.51
You save:  zł145.58
Already have an account? Log In

Transcript

Hello in this JavaScript programming tutorial I am going to show you class inheritance. So class inheritance works similar in the way you know inheritance than it does in biology in humans where you know child come from mother and father and you know, inherit certain gene certain traits from your parents. Unlike, you know, genetic inheritance it's not kind of a free for all and you know, it's hard to predict exactly what you're you know, inherit, you know exactly what you're going to hear it in terms of classes you specify this. Okay, so class inheritance, we have this class right here called Boy, you know, what are the classes now what's the car with the bike, the boat vehicles. Now let's create a vehicle class to class. Cool, like so.

And let's go a step further. This conceptual in Here we will add a constructor into any of these, we'll just leave it like this. So okay, that is cool. Let's create a function here. Let's just call this vehicle funk. And we'll just print something like console.

Log. Okay. Now, if we want color and nothing boy inherit from the vehicle class at the end here, the keyword extends the name of the class or copy and paste this up in the copy, paste it. Now if you run it, let's see what we have. Okay, so the first thing was Fine for this one is messing up. Because remember, we don't have a, you know, a different constructor for bike, it's still using the same one vehicle class.

So we need to specify some value. So the the initial X and Y coordinate on 00. Almost like the central graph, we know we got 00. This is a constructor, but haven't looked at this before. That's a good point. obj I think he did empty like there's nothing in here.

Oh, let's see if I do vehicle form. Save that. Refresh. Boom, there we go. This function is from the vehicle class, and as an extra test only to do the same but with the core object and you'll see that we are able to access all of the variables, the methods, the properties of the template, not what's called parent and child classes, and an extra one I want you to do is go even a step further create another class that inherits from One of these classes, and there'll be a grandfather parent child in heritance. And you know, that's it for class inheritance, nothing more to it than that.

You can obviously have more variables and functions with complex functionality that accepts parameters to maybe you know, compute something returns a value doesn't really matter what you do. As long as you understand this is how inheritance works. We have a parent class, these two classes are inheriting from me, I literally have nothing on its own. Yeah, the constructor is there to do some things store, you know, a couple of variables, console as these three lines and then we have a function called vehicle. So that's it class inheritance. If you have any questions, feel free to drop me a message.

The GitHub link will be provided as well as all the source code and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.