1
00:00:00,780 --> 00:00:07,290
So now you want to actually show you how you can use these protected access modifier.

2
00:00:07,350 --> 00:00:07,790
OK.

3
00:00:07,860 --> 00:00:15,590
But always use the getters and setters in order to access the values of the instance variables.

4
00:00:15,620 --> 00:00:26,190
OK so a name as you can see name and then put into double quotes here color and then I actually put

5
00:00:26,250 --> 00:00:28,060
another plus operator here.

6
00:00:28,110 --> 00:00:32,940
And then again I can actually refer to the name of the color instance variable plus.

7
00:00:33,090 --> 00:00:35,580
And then again I put two double quotes here.

8
00:00:35,580 --> 00:00:37,340
So speed.

9
00:00:38,130 --> 00:00:39,040
OK.

10
00:00:39,510 --> 00:00:41,890
And that puts a plus operator here.

11
00:00:42,060 --> 00:00:43,540
Amount of speed.

12
00:00:44,310 --> 00:00:48,570
And then I put another plus operator here and I put two double quotes here.

13
00:00:49,110 --> 00:00:55,490
Power and then and then I put a plus operator here amount of power.

14
00:00:55,510 --> 00:00:56,760
OK.

15
00:00:57,380 --> 00:01:01,570
As you can see now this is going to actually turn these values.

16
00:01:01,610 --> 00:01:02,310
OK.

17
00:01:02,570 --> 00:01:08,820
So let's actually inside this our main activity that job I find here is instead of just calling these

18
00:01:08,850 --> 00:01:09,960
two string method.

19
00:01:10,220 --> 00:01:12,460
I can't call that out.

20
00:01:12,470 --> 00:01:14,710
Put some values to the screen Nevitt.

21
00:01:14,720 --> 00:01:15,290
OK.

22
00:01:15,470 --> 00:01:18,320
So let's actually run our project and see what happens.

23
00:01:18,320 --> 00:01:22,960
So as you can see here these are the values that are outputted to the screen.

24
00:01:23,000 --> 00:01:24,540
OK name my chat.

25
00:01:24,740 --> 00:01:33,530
So let's actually go inside this Chatz class here as you can see Name Is My chat's color is white and

26
00:01:33,980 --> 00:01:34,680
speed.

27
00:01:34,940 --> 00:01:38,200
As you can see he's 40 and power is 50.

28
00:01:38,270 --> 00:01:38,830
OK.

29
00:01:38,960 --> 00:01:45,220
And let's actually go ahead and actually put our implementation's inside this lower class.

30
00:01:45,230 --> 00:01:46,150
OK.

31
00:01:46,790 --> 00:01:54,480
So now let me actually point out that always allow other classes to access your instance variables by

32
00:01:54,490 --> 00:01:56,800
using the getters and setters.

33
00:01:56,810 --> 00:01:57,460
OK.

34
00:01:57,740 --> 00:02:05,540
So let's actually change these protected access modifiers to privates because in this way our codes

35
00:02:05,600 --> 00:02:06,750
are more secure.

36
00:02:06,820 --> 00:02:07,590
OK.

37
00:02:07,760 --> 00:02:14,120
And we can actually restrict the access to these instance variables by just creating getters and setters

38
00:02:14,750 --> 00:02:19,190
so that other classes can not directly access these private parts.

39
00:02:19,190 --> 00:02:19,820
OK.

40
00:02:19,940 --> 00:02:21,400
So hopefully that makes sense.

41
00:02:21,650 --> 00:02:24,360
And let's go actually inside this lion class.

42
00:02:24,410 --> 00:02:31,700
And as you know the lion is actually part of the it's actually part of the Chadha family animals.

43
00:02:31,700 --> 00:02:32,340
OK.

44
00:02:32,570 --> 00:02:42,970
So we can actually say that a lion is a cat's OK extends Chatz OK.

45
00:02:43,960 --> 00:02:52,270
So as you can see here now our lion class is actually inheriting all of the features and behaviors that

46
00:02:52,270 --> 00:02:54,010
are inside this cat class.

47
00:02:54,010 --> 00:02:54,660
OK.

48
00:02:54,670 --> 00:03:02,360
So here inside this class I can actually create some instance variables that are only special to display

49
00:03:02,360 --> 00:03:02,940
in class.

50
00:03:03,040 --> 00:03:06,190
For example Ilyin is a brave animal.

51
00:03:06,460 --> 00:03:15,440
So I can actually create a boolean variable private boolean is brai OK.

52
00:03:15,710 --> 00:03:16,770
And then I.

53
00:03:16,940 --> 00:03:19,590
And then I put a semicolon at the end of this statement here.

54
00:03:19,610 --> 00:03:20,290
OK.

55
00:03:20,690 --> 00:03:27,890
So now as you can see these are characteristic is only specific to display in class.

56
00:03:27,890 --> 00:03:28,820
OK.

57
00:03:28,850 --> 00:03:33,580
So here I can actually create a constructor for this class.

58
00:03:33,590 --> 00:03:39,260
So first of all I need to actually put the public access modifier here and then I need to actually specify

59
00:03:39,590 --> 00:03:43,610
the name of my constructor for this line class.

60
00:03:43,640 --> 00:03:48,500
So the name of this constructor must be the same as the name of this line class.

61
00:03:48,500 --> 00:03:48,810
OK.

62
00:03:48,820 --> 00:03:49,990
Lion.

63
00:03:50,420 --> 00:03:56,900
And then I put up around brackets after my constructor name and then I open and close my constructor

64
00:03:57,110 --> 00:03:58,870
by using these curly braces.

65
00:03:58,880 --> 00:04:04,020
So inside the prentices as you can see we need to actually specify some arguments.

66
00:04:04,130 --> 00:04:07,070
Otherwise the Android studio is going to actually complain.

67
00:04:07,160 --> 00:04:11,170
Let's actually cover our mouse pointer over this error area.

68
00:04:11,360 --> 00:04:18,650
There is no default constructor available in chat class as you can see that example that Matas I saw

69
00:04:18,650 --> 00:04:20,680
that that app for that chat.

70
00:04:20,840 --> 00:04:28,160
So let's go actually inside this math class as you can see we've got our custom constructor inside this

71
00:04:28,160 --> 00:04:28,780
class.

72
00:04:28,790 --> 00:04:29,100
OK.

73
00:04:29,120 --> 00:04:30,830
There is no default constructor.

74
00:04:30,950 --> 00:04:37,220
So we need to actually initialize the constructor that is inside this class because we are inheriting

75
00:04:38,230 --> 00:04:41,100
the behaviors and features that are inside that class.

76
00:04:41,110 --> 00:04:41,650
OK.

77
00:04:41,950 --> 00:04:49,610
So here I can just typing super And then inside Apprentice's I need to actually pass these values up.

78
00:04:49,630 --> 00:04:51,970
Name Caller amount of speed.

79
00:04:51,970 --> 00:04:57,680
Amount of power or number of legs and can hunt other animals which is a boolean value.

80
00:04:57,690 --> 00:05:04,090
OK so here I can actually specify some arguments for this constructor.

81
00:05:04,290 --> 00:05:04,760
OK.

82
00:05:04,840 --> 00:05:10,960
So that whenever we actually create an object from this lower class we need to pass those values to

83
00:05:10,960 --> 00:05:12,370
the constructor OK.

84
00:05:12,640 --> 00:05:16,060
So the first value is going to be the name.

85
00:05:16,470 --> 00:05:19,870
OK so strange name.

86
00:05:20,140 --> 00:05:27,520
And the second argument is again color and our first argument is of type int and the name of that argument

87
00:05:27,520 --> 00:05:30,840
is amount of speed.

88
00:05:31,140 --> 00:05:40,370
Ok comma in that amount of power comma.

89
00:05:40,780 --> 00:05:47,320
So let's actually go inside this cat class in order to see other values other arguments so name caller

90
00:05:47,920 --> 00:05:48,720
amount of speed.

91
00:05:48,730 --> 00:05:52,260
Amount of power a number of legs can hunt other animals.

92
00:05:52,270 --> 00:05:53,150
OK.

93
00:05:53,540 --> 00:05:58,940
Int number of legs.

94
00:05:59,470 --> 00:06:00,190
OK.

95
00:06:00,430 --> 00:06:05,130
Boullion can haunt other animals.

96
00:06:05,140 --> 00:06:06,040
OK.

97
00:06:09,030 --> 00:06:16,770
So let's actually create a new line here in order to actually see these are arguments better.

98
00:06:16,800 --> 00:06:17,570
OK.

99
00:06:17,970 --> 00:06:21,810
And we have another instance variable which is specific.

100
00:06:21,840 --> 00:06:23,690
Only two these are like in class.

101
00:06:23,700 --> 00:06:24,500
OK.

102
00:06:24,510 --> 00:06:25,520
Is brief.

103
00:06:25,650 --> 00:06:28,750
So boolean is brave.

104
00:06:28,860 --> 00:06:29,360
OK.

105
00:06:29,430 --> 00:06:34,960
So here in say the apprentice's of the superhero I can just pass these values.

106
00:06:34,980 --> 00:06:35,370
OK.

107
00:06:35,400 --> 00:06:47,100
Name comma color comma amount of speed comma and out of power comma.

108
00:06:47,430 --> 00:06:52,910
Number of Lex comma and can hunt other animals.

109
00:06:53,210 --> 00:06:53,980
OK.

110
00:06:54,270 --> 00:06:57,750
So as you can see here these are the arguments.

111
00:06:57,750 --> 00:07:02,950
These are the values that we specified for this chat class.

112
00:07:02,970 --> 00:07:03,540
OK.

113
00:07:03,750 --> 00:07:11,430
As you can see here these are the arguments that we specified for this cat class yet he conceived for

114
00:07:11,430 --> 00:07:16,310
this for the constructor of this Kathe Class VI is specified these arguments.

115
00:07:16,320 --> 00:07:18,730
Ok name caller amount of speed.

116
00:07:18,750 --> 00:07:22,620
Amount of power number of legs and can hunt other animals.

117
00:07:22,830 --> 00:07:28,800
So because this lion class is actually inheriting all of those are features and behaviors that are inside

118
00:07:28,800 --> 00:07:32,790
this cat class into this lion class here.

119
00:07:32,890 --> 00:07:37,480
We need to actually initialize the constructor of the superclass.

120
00:07:37,530 --> 00:07:41,740
OK so this super refers to this chat class here.

121
00:07:41,820 --> 00:07:42,470
OK.

122
00:07:42,810 --> 00:07:48,570
And we need to actually first of all initialize the constructor of this class and then we can actually

123
00:07:48,570 --> 00:07:51,900
initialize our own instance variable here.

124
00:07:51,900 --> 00:08:00,260
So first I just need to type in this in order to refer to this lower class that is brief assignment

125
00:08:00,300 --> 00:08:04,370
operator and here I can I truly referred to this argument here.

126
00:08:04,370 --> 00:08:06,040
OK it is brave.

127
00:08:06,180 --> 00:08:13,350
Now as you can see I initialized my own r instance variable here my own instance variable inside this

128
00:08:13,350 --> 00:08:14,780
line class OK.

129
00:08:15,180 --> 00:08:20,560
And here in this line of code I initialized the constructor of the superclass.

130
00:08:20,750 --> 00:08:26,540
OK so that I don't need to actually redeclare these instance variables inside this class.

131
00:08:26,550 --> 00:08:30,800
So again that's the power of inheritance with just one line of code.

132
00:08:30,940 --> 00:08:36,930
We actually managed to initialize all all of these instance variables OK and we didn't declare these

133
00:08:36,930 --> 00:08:43,170
instance variables and we just inherited all of these instance variables and we can use them.

134
00:08:43,310 --> 00:08:43,900
OK.

135
00:08:44,050 --> 00:08:50,480
And I can actually create a set here and I'll get her Meffert for this is brave instance variable.

136
00:08:50,580 --> 00:08:57,540
Again I'd like to clear out of this constructor here and inside this in class I wrote click here and

137
00:08:57,540 --> 00:09:05,700
then I click on generate and then I click on get her and set her and here choose this is brave instance

138
00:09:05,700 --> 00:09:07,680
variable here and then click on OK.

139
00:09:08,030 --> 00:09:08,730
OK.

140
00:09:09,090 --> 00:09:14,640
So as you can see here this is our Get here for this instance variable is brave.

141
00:09:14,760 --> 00:09:17,940
And this is our set here for this instance variable.

142
00:09:18,180 --> 00:09:20,820
So I don't like this name here is brave.

143
00:09:20,820 --> 00:09:24,140
So let's actually change this number to get brave.

144
00:09:24,150 --> 00:09:25,280
OK.

145
00:09:25,650 --> 00:09:27,370
So hopefully that makes sense.

146
00:09:27,810 --> 00:09:34,500
And now I want to actually override the twisting method that I actually inherit from the Object class.

147
00:09:34,500 --> 00:09:34,990
OK.

148
00:09:35,160 --> 00:09:37,070
So I just need to type in here two was three.

149
00:09:37,110 --> 00:09:40,040
Now we can actually override this method.

150
00:09:40,050 --> 00:09:42,480
So let's actually delete this line of code here.

151
00:09:42,600 --> 00:09:50,250
We can actually inherit the implementations that are inside this Kathe class here.

152
00:09:50,290 --> 00:09:50,770
OK.

153
00:09:50,830 --> 00:09:54,920
As you can see we did actually put this code here.

154
00:09:55,090 --> 00:10:04,200
So now we can actually use this code inside this line class by just typing in return super dot to think.

