Inheritance

8 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.94
List Price:  €92.78
You save:  €27.83
£55.57
List Price:  £79.40
You save:  £23.82
CA$95.27
List Price:  CA$136.11
You save:  CA$40.83
A$107.88
List Price:  A$154.13
You save:  A$46.24
S$94.55
List Price:  S$135.08
You save:  S$40.52
HK$547.57
List Price:  HK$782.28
You save:  HK$234.71
CHF 63.42
List Price:  CHF 90.61
You save:  CHF 27.18
NOK kr759.63
List Price:  NOK kr1,085.23
You save:  NOK kr325.60
DKK kr484.38
List Price:  DKK kr692.01
You save:  DKK kr207.62
NZ$117.46
List Price:  NZ$167.80
You save:  NZ$50.34
د.إ257.02
List Price:  د.إ367.19
You save:  د.إ110.16
৳7,682.93
List Price:  ৳10,976.08
You save:  ৳3,293.15
₹5,837.41
List Price:  ₹8,339.52
You save:  ₹2,502.10
RM331.26
List Price:  RM473.25
You save:  RM141.99
₦99,285.71
List Price:  ₦141,842.81
You save:  ₦42,557.10
₨19,466.20
List Price:  ₨27,810.04
You save:  ₨8,343.84
฿2,553.28
List Price:  ฿3,647.70
You save:  ฿1,094.41
₺2,262.39
List Price:  ₺3,232.12
You save:  ₺969.73
B$349.43
List Price:  B$499.21
You save:  B$149.77
R1,335.92
List Price:  R1,908.54
You save:  R572.62
Лв126.45
List Price:  Лв180.65
You save:  Лв54.20
₩94,634.34
List Price:  ₩135,197.71
You save:  ₩40,563.37
₪258.03
List Price:  ₪368.63
You save:  ₪110.60
₱3,943.57
List Price:  ₱5,633.91
You save:  ₱1,690.34
¥10,600.67
List Price:  ¥15,144.47
You save:  ¥4,543.79
MX$1,161.53
List Price:  MX$1,659.40
You save:  MX$497.87
QR255
List Price:  QR364.31
You save:  QR109.30
P959.59
List Price:  P1,370.91
You save:  P411.31
KSh9,203.68
List Price:  KSh13,148.68
You save:  KSh3,945
E£3,310.52
List Price:  E£4,729.52
You save:  E£1,419
ብር3,976.27
List Price:  ብር5,680.63
You save:  ብር1,704.36
Kz58,526.41
List Price:  Kz83,612.74
You save:  Kz25,086.33
CLP$68,581.80
List Price:  CLP$97,978.20
You save:  CLP$29,396.40
CN¥506.04
List Price:  CN¥722.95
You save:  CN¥216.90
RD$4,144.87
List Price:  RD$5,921.50
You save:  RD$1,776.62
DA9,443.17
List Price:  DA13,490.83
You save:  DA4,047.65
FJ$158.28
List Price:  FJ$226.12
You save:  FJ$67.84
Q545.87
List Price:  Q779.86
You save:  Q233.98
GY$14,645.83
List Price:  GY$20,923.51
You save:  GY$6,277.68
ISK kr9,762.20
List Price:  ISK kr13,946.60
You save:  ISK kr4,184.40
DH709.20
List Price:  DH1,013.19
You save:  DH303.99
L1,234.28
List Price:  L1,763.34
You save:  L529.05
ден3,991.30
List Price:  ден5,702.11
You save:  ден1,710.80
MOP$564.10
List Price:  MOP$805.89
You save:  MOP$241.79
N$1,325.35
List Price:  N$1,893.44
You save:  N$568.09
C$2,576.69
List Price:  C$3,681.15
You save:  C$1,104.45
रु9,334.54
List Price:  रु13,335.63
You save:  रु4,001.09
S/259.58
List Price:  S/370.84
You save:  S/111.26
K267.89
List Price:  K382.72
You save:  K114.82
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,765.85
List Price:  ZK2,522.76
You save:  ZK756.90
L322.98
List Price:  L461.43
You save:  L138.44
Kč1,645.46
List Price:  Kč2,350.75
You save:  Kč705.29
Ft25,709.21
List Price:  Ft36,729.02
You save:  Ft11,019.81
SEK kr749.87
List Price:  SEK kr1,071.30
You save:  SEK kr321.42
ARS$60,034.20
List Price:  ARS$85,766.82
You save:  ARS$25,732.62
Bs483.70
List Price:  Bs691.04
You save:  Bs207.33
COP$271,296.95
List Price:  COP$387,583.68
You save:  COP$116,286.73
₡35,581.11
List Price:  ₡50,832.34
You save:  ₡15,251.22
L1,728.07
List Price:  L2,468.78
You save:  L740.71
₲516,441.87
List Price:  ₲737,805.73
You save:  ₲221,363.85
$U2,647.22
List Price:  $U3,781.90
You save:  $U1,134.68
zł280.50
List Price:  zł400.73
You save:  zł120.23
Already have an account? Log In

Transcript

Thank you for coming back to the course. In this lesson, we are going to talk about a very important concept, which is inheritance. Like in our example, we are going to create different kinds of witches, like therefore witch and the fire witch. Although they are different types of witches, they both belong to the same witch family and they inherit the witch properties. Let's do an example. We create a base class which and then we divide the initialization function.

The initialization function again will take three parameters and the first parameter will be by default itself. The other two parameters name and therefore, we are going to assign that to the self dot name self dot level, which belongs to the cast and then we will define the witchcraft On the score attack function same as what we have done in our previous lessons, we will return random dot when in and then from one to 10 and then multiply by the level of the witch. So, this is our basic which, after that, we are going to create the subclass of which these subclass have which is going to inherit the property from the parent which cast and it also needs to have the initialization function which is going to take four parameters. The first one of course, is itself and then name level but this time we have one more extra parameter, which is defying stuff for the fire which to attack And then since fi which is a subclass of which it will have SS of the functions defined in the parent class in order to initialize the variable name and therefore, we just have to call super dot init it this will trigger the initialization function of the pen cast.

Now, the super function we use here is referring to the parent cast which, so, when we call super.in it we are calling the init function of the parent object and we pass in name and nevel as the parameter this will then trigger the init function defined in the parent class. After that, since we have one extra parameter for this in the future We just need to add self dot find stuff equals to the past in time to buy stuff and then that will be fine. After that, we are going to override the witch calf attack function from the parent class. So, we will define a function with the same name. And then we will put base attack equals to Super dot witchcraft attack. Again this super function is calling the parent which cast and then the witch cop attack function of the parent which cast that means it is going to generate a random number and return that back to the base attack wearable after that, We will check if self talk five stuff equals to true.

This is to see if the file which here has defined stuff. If it has five stuff, we will play now which calf is filling with fire. So the attacker is going to be much more powerful. Therefore, we will return the base attack multi by by two. So the attack is double else we will return just base attack because this attack doesn't really fire. Now we have the parent costs and the sub costs We will then import the random package.

And then we instantiate the FFI which object, we of course have to pass in the name of the file which, and then the level, which we default that to five. Now we have to pass in the HR parameter, find stuff, which is a true or false value. We can nephesh the same random package, but this time we use the choice function. You have Python to select from either true or false. So the whole initialization process goes nighties. We try to create a file which object then we pass in the parameter, five which five and a random choice this will trigger The initialization function of the file which costs five which will be passed yourself, the name will be passed to the name, five to be passed to the level and the phi stuff is going to be a random value of either true or false.

This initialization will instead call the initialization function of the superclass, which is the parent class. And then the name and level is going to be assigned to the object where we oppose. Next, it is going to assign the five star parameter to the FASTA variable. Now let's check if we have the name and the level of the fire which defined properly. Between these two, you see we have five which and five as the level and then we try to clean out the fine stuff. Okay.

Which doesn't have the fire stuff. And then we trigger the function which quaff attack. And we see that this time we have an attack where you have 20. So what's happening here is the which half attack function of the fire which cause has been trigger and the base attack value is coming from the parent class. The self level multiplied by the random number. After that, we check whether the rich has a fast enough because the which doesn't have the Fast Start, so it goes to the else condition and therefore we have a base attack value of 20.

Now next create an other file which will be triggered the witchcraft function naturally can attack with fire. Let's check if it is because this file which has a file staff, we find that the result is true. So all makes sense because the fine stuff for these five which is true, so that's why it free now it is attacking with fire and the base attack value is doubled. So that's all about today. See you next lesson.

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.