Tan115 commited on
Commit
eea1483
·
verified ·
1 Parent(s): 78b4844

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +12 -0
  2. 02 - Core Java/006 How Java Works.mp4 +3 -0
  3. 02 - Core Java/007 Variables.mp4 +3 -0
  4. 02 - Core Java/010 Type Conversion.mp4 +3 -0
  5. 02 - Core Java/012 Arithmetic Operators.mp4 +3 -0
  6. 02 - Core Java/013 Relational Operators.mp4 +3 -0
  7. 02 - Core Java/014 Logical Operators.mp4 +3 -0
  8. 02 - Core Java/015 If Else.mp4 +3 -0
  9. 02 - Core Java/016 If Else If.mp4 +3 -0
  10. 02 - Core Java/017 Ternary.mp4 +3 -0
  11. 02 - Core Java/018 Switch Statement.mp4 +3 -0
  12. 02 - Core Java/019 Need For Loop.mp4 +3 -0
  13. 02 - Core Java/021 Do While Loop.mp4 +3 -0
  14. 02 - Core Java/039 Mutable vs Immutable string_en.srt +688 -0
  15. 02 - Core Java/039 Source-code.url +2 -0
  16. 02 - Core Java/040 Source-code.url +2 -0
  17. 02 - Core Java/040 StringBuffer and StringBuilder_en.srt +620 -0
  18. 02 - Core Java/041 Source-code.url +2 -0
  19. 02 - Core Java/041 Static Variable_en.srt +700 -0
  20. 02 - Core Java/042 Source-code.url +2 -0
  21. 02 - Core Java/042 Static method_en.srt +508 -0
  22. 02 - Core Java/043 Source-code.url +2 -0
  23. 02 - Core Java/043 Static block_en.srt +800 -0
  24. 02 - Core Java/044 Encapsulation_en.srt +1144 -0
  25. 02 - Core Java/044 Source-code.url +2 -0
  26. 02 - Core Java/045 Getters and setters_en.srt +328 -0
  27. 02 - Core Java/045 Source-code.url +2 -0
  28. 02 - Core Java/046 Source-code.url +2 -0
  29. 02 - Core Java/046 This keyword_en.srt +908 -0
  30. 02 - Core Java/047 Constructor_en.srt +736 -0
  31. 02 - Core Java/047 Source-code.url +2 -0
  32. 02 - Core Java/048 Default vs Parameterized Constructor_en.srt +520 -0
  33. 02 - Core Java/048 Source-code.url +2 -0
  34. 02 - Core Java/049 Naming Convention_en.srt +440 -0
  35. 02 - Core Java/049 Source-code.url +2 -0
  36. 02 - Core Java/050 Anonymous Object_en.srt +508 -0
  37. 02 - Core Java/050 Source-code.url +2 -0
  38. 02 - Core Java/051 Source-code.url +2 -0
  39. 02 - Core Java/051 What is Inheritance_en.srt +848 -0
  40. 02 - Core Java/052 Need of Inheritance_en.srt +664 -0
  41. 02 - Core Java/052 Source-code.url +2 -0
  42. 02 - Core Java/053 Single and Multilevel inheritance_en.srt +396 -0
  43. 02 - Core Java/053 Source-code.url +2 -0
  44. 02 - Core Java/054 Multiple Inheritance_en.srt +656 -0
  45. 02 - Core Java/054 Source-code.url +2 -0
  46. 02 - Core Java/055 Source-code.url +2 -0
  47. 02 - Core Java/055 This and super method_en.srt +1204 -0
  48. 02 - Core Java/056 Method Overriding_en.srt +808 -0
  49. 02 - Core Java/056 Source-code.url +2 -0
  50. 02 - Core Java/057 Packages_en.srt +1252 -0
.gitattributes CHANGED
@@ -41,3 +41,15 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
41
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/005[[:space:]]First[[:space:]]code[[:space:]]Setup.mp4 filter=lfs diff=lfs merge=lfs -text
42
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/009[[:space:]]Literal.mp4 filter=lfs diff=lfs merge=lfs -text
43
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/008[[:space:]]Data[[:space:]]Types.mp4 filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/005[[:space:]]First[[:space:]]code[[:space:]]Setup.mp4 filter=lfs diff=lfs merge=lfs -text
42
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/009[[:space:]]Literal.mp4 filter=lfs diff=lfs merge=lfs -text
43
  02[[:space:]]-[[:space:]]Core[[:space:]]Java/008[[:space:]]Data[[:space:]]Types.mp4 filter=lfs diff=lfs merge=lfs -text
44
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/006[[:space:]]How[[:space:]]Java[[:space:]]Works.mp4 filter=lfs diff=lfs merge=lfs -text
45
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/007[[:space:]]Variables.mp4 filter=lfs diff=lfs merge=lfs -text
46
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/012[[:space:]]Arithmetic[[:space:]]Operators.mp4 filter=lfs diff=lfs merge=lfs -text
47
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/010[[:space:]]Type[[:space:]]Conversion.mp4 filter=lfs diff=lfs merge=lfs -text
48
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/013[[:space:]]Relational[[:space:]]Operators.mp4 filter=lfs diff=lfs merge=lfs -text
49
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/015[[:space:]]If[[:space:]]Else.mp4 filter=lfs diff=lfs merge=lfs -text
50
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/014[[:space:]]Logical[[:space:]]Operators.mp4 filter=lfs diff=lfs merge=lfs -text
51
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/016[[:space:]]If[[:space:]]Else[[:space:]]If.mp4 filter=lfs diff=lfs merge=lfs -text
52
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/017[[:space:]]Ternary.mp4 filter=lfs diff=lfs merge=lfs -text
53
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/018[[:space:]]Switch[[:space:]]Statement.mp4 filter=lfs diff=lfs merge=lfs -text
54
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/021[[:space:]]Do[[:space:]]While[[:space:]]Loop.mp4 filter=lfs diff=lfs merge=lfs -text
55
+ 02[[:space:]]-[[:space:]]Core[[:space:]]Java/019[[:space:]]Need[[:space:]]For[[:space:]]Loop.mp4 filter=lfs diff=lfs merge=lfs -text
02 - Core Java/006 How Java Works.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9aa724697127c337f5df4574bb9c27eeade3a68cd54d2dd18a61e86226550fd0
3
+ size 127336724
02 - Core Java/007 Variables.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ce88ef29ca96761dda3ea1dcf55857cf07399f447ecf0afd451e2f43adc5a75
3
+ size 218963038
02 - Core Java/010 Type Conversion.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f62562a79f793cea12e6e41ec3e783e27bc252afa283c20bd8717112f358eea
3
+ size 94369188
02 - Core Java/012 Arithmetic Operators.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1371ddb937f01079c957041f72e6f16b0a71d9f43e65ce02f79d5581085d8377
3
+ size 52178681
02 - Core Java/013 Relational Operators.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a6e74a3f8afd707291119795eeb4e61e8af605f9375fae1c4de98b448138d90
3
+ size 62286093
02 - Core Java/014 Logical Operators.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e2fdfa710946f18edef5cd7c1240c530e2b2b3eec800431f39e5579d635bf5a
3
+ size 158452971
02 - Core Java/015 If Else.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64b8a0b2e85fcb76f130337f4f011d1c1bd832d801dfe6120fbba12f58032acf
3
+ size 58497706
02 - Core Java/016 If Else If.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b310e06d124fe76713875dc998e3b70979bd8b0c4207667891a9be0011f1f97f
3
+ size 80802646
02 - Core Java/017 Ternary.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad2004a559981fe83482a7ac7cdc349948b80c834e1b47f44781b4a8c04198ac
3
+ size 23421354
02 - Core Java/018 Switch Statement.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:858aed8380f77a1b65531c34634a8cd7ed8346407f5d692ac7c46058a0396ddc
3
+ size 131214725
02 - Core Java/019 Need For Loop.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:336307e365a5dfd3ca7c999173c1e8044c5623a4c71ee3e69a40c92742a228b4
3
+ size 59499341
02 - Core Java/021 Do While Loop.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5bb0c1ccc7da587425f1b1e11bde5e3fbcf019954ba34b126371d30292519df
3
+ size 49889788
02 - Core Java/039 Mutable vs Immutable string_en.srt ADDED
@@ -0,0 +1,688 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:04,000
7
+ -: So in the previous video we have talked
8
+
9
+ 3
10
+ 00:00:04,000 --> 00:00:05,000
11
+ about string, right?
12
+
13
+ 4
14
+ 00:00:05,000 --> 00:00:08,000
15
+ Now we talk about this string,
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:10,000
19
+ what might be happening behind the scene.
20
+
21
+ 6
22
+ 00:00:10,000 --> 00:00:11,000
23
+ Example, let's say if you store this navin,
24
+
25
+ 7
26
+ 00:00:11,000 --> 00:00:15,000
27
+ of course it'll be getting stored in the heap memory.
28
+
29
+ 8
30
+ 00:00:15,000 --> 00:00:16,000
31
+ But now what I wanna do is
32
+
33
+ 9
34
+ 00:00:16,000 --> 00:00:17,000
35
+ before printing navin here,
36
+
37
+ 10
38
+ 00:00:17,000 --> 00:00:19,000
39
+ let's say I want to append something.
40
+
41
+ 11
42
+ 00:00:19,000 --> 00:00:22,000
43
+ So I would say name is equal to,
44
+
45
+ 12
46
+ 00:00:22,000 --> 00:00:25,000
47
+ I want to add my name with, let's say reddy here.
48
+
49
+ 13
50
+ 00:00:25,000 --> 00:00:26,000
51
+ I'm giving a space
52
+
53
+ 14
54
+ 00:00:26,000 --> 00:00:28,000
55
+ so that we can differentiate these two words.
56
+
57
+ 15
58
+ 00:00:28,000 --> 00:00:30,000
59
+ So of course now when I say name,
60
+
61
+ 16
62
+ 00:00:30,000 --> 00:00:32,000
63
+ it'll be Navin Reddy, right?
64
+
65
+ 17
66
+ 00:00:32,000 --> 00:00:34,000
67
+ So basically we are trying to change the value.
68
+
69
+ 18
70
+ 00:00:34,000 --> 00:00:36,000
71
+ Now if we talk about integer, float, double.
72
+
73
+ 19
74
+ 00:00:36,000 --> 00:00:38,000
75
+ Basically you can change values of it, right?
76
+
77
+ 20
78
+ 00:00:38,000 --> 00:00:39,000
79
+ And it actually makes sense.
80
+
81
+ 21
82
+ 00:00:39,000 --> 00:00:42,000
83
+ That's why we call them as variables.
84
+
85
+ 22
86
+ 00:00:42,000 --> 00:00:43,000
87
+ And here also, we are trying to do that.
88
+
89
+ 23
90
+ 00:00:43,000 --> 00:00:46,000
91
+ But first of all, let's check if this works.
92
+
93
+ 24
94
+ 00:00:46,000 --> 00:00:50,000
95
+ So if I go back and compile and run, it works.
96
+
97
+ 25
98
+ 00:00:50,000 --> 00:00:51,000
99
+ You can see that the new data
100
+
101
+ 26
102
+ 00:00:51,000 --> 00:00:52,000
103
+ for the navin is navin reddy, right?
104
+
105
+ 27
106
+ 00:00:52,000 --> 00:00:54,000
107
+ And that works.
108
+
109
+ 28
110
+ 00:00:54,000 --> 00:00:56,000
111
+ But what if I say that's not the case?
112
+
113
+ 29
114
+ 00:00:56,000 --> 00:00:59,000
115
+ You're not changing the existing string.
116
+
117
+ 30
118
+ 00:00:59,000 --> 00:01:00,000
119
+ Let me repeat.
120
+
121
+ 31
122
+ 00:01:00,000 --> 00:01:04,000
123
+ You are not changing from navin to navin reddy?
124
+
125
+ 32
126
+ 00:01:04,000 --> 00:01:07,000
127
+ So if you're thinking there will be a variable here
128
+
129
+ 33
130
+ 00:01:07,000 --> 00:01:10,000
131
+ where you have Navin, you're making it Navin Reddy.
132
+
133
+ 34
134
+ 00:01:10,000 --> 00:01:12,000
135
+ No, that's not the case.
136
+
137
+ 35
138
+ 00:01:12,000 --> 00:01:14,000
139
+ That's not how string works.
140
+
141
+ 36
142
+ 00:01:14,000 --> 00:01:15,000
143
+ Okay, so what happens?
144
+
145
+ 37
146
+ 00:01:15,000 --> 00:01:18,000
147
+ So what I will do is I'll just remove this part now.
148
+
149
+ 38
150
+ 00:01:18,000 --> 00:01:20,000
151
+ So what is happening, basically,
152
+
153
+ 39
154
+ 00:01:20,000 --> 00:01:23,000
155
+ you know, since strings are used heavily in Java,
156
+
157
+ 40
158
+ 00:01:23,000 --> 00:01:26,000
159
+ now most of the time you try to reuse the strings,
160
+
161
+ 41
162
+ 00:01:26,000 --> 00:01:28,000
163
+ the same string, you'll be using multiple times.
164
+
165
+ 42
166
+ 00:01:28,000 --> 00:01:31,000
167
+ Example, let's say, before I show you something,
168
+
169
+ 43
170
+ 00:01:31,000 --> 00:01:33,000
171
+ let's say, I create a string here,
172
+
173
+ 44
174
+ 00:01:33,000 --> 00:01:37,000
175
+ which is s1 is equal to Navin.
176
+
177
+ 45
178
+ 00:01:37,000 --> 00:01:38,000
179
+ And you can see we have a capital N this time.
180
+
181
+ 46
182
+ 00:01:38,000 --> 00:01:41,000
183
+ So this two data are actually different, okay?
184
+
185
+ 47
186
+ 00:01:41,000 --> 00:01:44,000
187
+ So I will say string s2 is equal to,
188
+
189
+ 48
190
+ 00:01:44,000 --> 00:01:45,000
191
+ and I will say Navin again.
192
+
193
+ 49
194
+ 00:01:45,000 --> 00:01:47,000
195
+ Now, what do you think?
196
+
197
+ 50
198
+ 00:01:47,000 --> 00:01:50,000
199
+ How many objects we are creating behind the scene?
200
+
201
+ 51
202
+ 00:01:50,000 --> 00:01:51,000
203
+ Think about this.
204
+
205
+ 52
206
+ 00:01:51,000 --> 00:01:51,000
207
+ Okay?
208
+
209
+ 53
210
+ 00:01:51,000 --> 00:01:53,000
211
+ So if you're thinking, we got two objects,
212
+
213
+ 54
214
+ 00:01:53,000 --> 00:01:57,000
215
+ actually not, we got two references.
216
+
217
+ 55
218
+ 00:01:57,000 --> 00:01:58,000
219
+ We got s1, s2.
220
+
221
+ 56
222
+ 00:01:58,000 --> 00:02:02,000
223
+ Of course, in your stack, you'll be having s1, s2 here,
224
+
225
+ 57
226
+ 00:02:02,000 --> 00:02:06,000
227
+ but in total, you got only one object.
228
+
229
+ 58
230
+ 00:02:08,000 --> 00:02:09,000
231
+ And that sounds tricky here, right?
232
+
233
+ 59
234
+ 00:02:09,000 --> 00:02:11,000
235
+ And let me prove that point to you.
236
+
237
+ 60
238
+ 00:02:11,000 --> 00:02:13,000
239
+ See, what I want to prove is the value
240
+
241
+ 61
242
+ 00:02:13,000 --> 00:02:15,000
243
+ for this field and this field will be equal.
244
+
245
+ 62
246
+ 00:02:15,000 --> 00:02:17,000
247
+ The way the I can do that is by saying S out,
248
+
249
+ 63
250
+ 00:02:17,000 --> 00:02:22,000
251
+ s1 is equal to equal to s2.
252
+
253
+ 64
254
+ 00:02:22,000 --> 00:02:25,000
255
+ If this is true, then they are same.
256
+
257
+ 65
258
+ 00:02:25,000 --> 00:02:27,000
259
+ So if I run, you can see we got true.
260
+
261
+ 66
262
+ 00:02:27,000 --> 00:02:31,000
263
+ That means the value for the addresses are same.
264
+
265
+ 67
266
+ 00:02:31,000 --> 00:02:33,000
267
+ In total we got only one object.
268
+
269
+ 68
270
+ 00:02:33,000 --> 00:02:37,000
271
+ So here what happens is we have a special area
272
+
273
+ 69
274
+ 00:02:37,000 --> 00:02:39,000
275
+ inside your heap memory.
276
+
277
+ 70
278
+ 00:02:39,000 --> 00:02:42,000
279
+ So this is your heap, that's your JVM,
280
+
281
+ 71
282
+ 00:02:42,000 --> 00:02:44,000
283
+ and that's your stack.
284
+
285
+ 72
286
+ 00:02:44,000 --> 00:02:45,000
287
+ So inside your heap,
288
+
289
+ 73
290
+ 00:02:45,000 --> 00:02:50,000
291
+ you'll be having a special area called string constant pool.
292
+
293
+ 74
294
+ 00:02:51,000 --> 00:02:54,000
295
+ And by the name itself you can see it says constant.
296
+
297
+ 75
298
+ 00:02:54,000 --> 00:02:55,000
299
+ That's right.
300
+
301
+ 76
302
+ 00:02:55,000 --> 00:02:58,000
303
+ Every string which you create, which you use in Java,
304
+
305
+ 77
306
+ 00:02:58,000 --> 00:03:01,000
307
+ which is a string literal is actually a constant.
308
+
309
+ 78
310
+ 00:03:01,000 --> 00:03:01,000
311
+ You can't change it.
312
+
313
+ 79
314
+ 00:03:01,000 --> 00:03:04,000
315
+ Example, if I write something like navin here,
316
+
317
+ 80
318
+ 00:03:04,000 --> 00:03:05,000
319
+ I cannot change it.
320
+
321
+ 81
322
+ 00:03:05,000 --> 00:03:06,000
323
+ It's done.
324
+
325
+ 82
326
+ 00:03:06,000 --> 00:03:08,000
327
+ It's navin everywhere, okay?
328
+
329
+ 83
330
+ 00:03:08,000 --> 00:03:10,000
331
+ So you can't change the data.
332
+
333
+ 84
334
+ 00:03:10,000 --> 00:03:12,000
335
+ So example, what happens is every time you try
336
+
337
+ 85
338
+ 00:03:12,000 --> 00:03:14,000
339
+ to use a variable here, example,
340
+
341
+ 86
342
+ 00:03:14,000 --> 00:03:16,000
343
+ if you execute the line number eight, it checks,
344
+
345
+ 87
346
+ 00:03:16,000 --> 00:03:18,000
347
+ okay, we need navin variable.
348
+
349
+ 88
350
+ 00:03:18,000 --> 00:03:21,000
351
+ Do we already have navin in the string constant pool?
352
+
353
+ 89
354
+ 00:03:21,000 --> 00:03:22,000
355
+ No, we don't have it.
356
+
357
+ 90
358
+ 00:03:22,000 --> 00:03:23,000
359
+ So let's create navin here.
360
+
361
+ 91
362
+ 00:03:23,000 --> 00:03:25,000
363
+ So it'll create a string variable, navin,
364
+
365
+ 92
366
+ 00:03:25,000 --> 00:03:27,000
367
+ it'll have some address, let's say 101,
368
+
369
+ 93
370
+ 00:03:27,000 --> 00:03:31,000
371
+ and then the name variable here will get this address.
372
+
373
+ 94
374
+ 00:03:31,000 --> 00:03:33,000
375
+ So this name variable is actually referring
376
+
377
+ 95
378
+ 00:03:33,000 --> 00:03:36,000
379
+ to this particular address, okay?
380
+
381
+ 96
382
+ 00:03:36,000 --> 00:03:38,000
383
+ Then it goes for the next statement.
384
+
385
+ 97
386
+ 00:03:38,000 --> 00:03:39,000
387
+ Let's execute this part.
388
+
389
+ 98
390
+ 00:03:39,000 --> 00:03:41,000
391
+ Let's ignore this line as of now,
392
+
393
+ 99
394
+ 00:03:41,000 --> 00:03:42,000
395
+ let's focus on line number 12 and 13.
396
+
397
+ 100
398
+ 00:03:42,000 --> 00:03:45,000
399
+ So line number 12 says, s1 is equal to Navin.
400
+
401
+ 101
402
+ 00:03:45,000 --> 00:03:46,000
403
+ Okay, so it checks,
404
+
405
+ 102
406
+ 00:03:46,000 --> 00:03:49,000
407
+ do we have navin with capital N in the string pool?
408
+
409
+ 103
410
+ 00:03:49,000 --> 00:03:50,000
411
+ No, we don't have it.
412
+
413
+ 104
414
+ 00:03:50,000 --> 00:03:52,000
415
+ So it'll create Navin here.
416
+
417
+ 105
418
+ 00:03:52,000 --> 00:03:54,000
419
+ And let's say the address is 103.
420
+
421
+ 106
422
+ 00:03:54,000 --> 00:03:57,000
423
+ So it'll store 103 here.
424
+
425
+ 107
426
+ 00:03:57,000 --> 00:03:58,000
427
+ Now that makes sense, right?
428
+
429
+ 108
430
+ 00:03:58,000 --> 00:04:00,000
431
+ And that's why you're referring to that particular location.
432
+
433
+ 109
434
+ 00:04:00,000 --> 00:04:02,000
435
+ Now, what happens on line number 13?
436
+
437
+ 110
438
+ 00:04:02,000 --> 00:04:05,000
439
+ Line number 13 says string s2 is equal to Navin.
440
+
441
+ 111
442
+ 00:04:05,000 --> 00:04:07,000
443
+ It'll go to string constant pool again
444
+
445
+ 112
446
+ 00:04:07,000 --> 00:04:09,000
447
+ and check, hey, do we have Navin with capital N?
448
+
449
+ 113
450
+ 00:04:09,000 --> 00:04:10,000
451
+ Yes, we do have.
452
+
453
+ 114
454
+ 00:04:10,000 --> 00:04:13,000
455
+ Now, it'll not create a new object for you,
456
+
457
+ 115
458
+ 00:04:13,000 --> 00:04:16,000
459
+ it'll simply use this address 103.
460
+
461
+ 116
462
+ 00:04:16,000 --> 00:04:17,000
463
+ Okay?
464
+
465
+ 117
466
+ 00:04:17,000 --> 00:04:18,000
467
+ And that's the beauty.
468
+
469
+ 118
470
+ 00:04:18,000 --> 00:04:20,000
471
+ That's how you're trying to save the memory.
472
+
473
+ 119
474
+ 00:04:20,000 --> 00:04:23,000
475
+ Otherwise you could have created multiple variables
476
+
477
+ 120
478
+ 00:04:23,000 --> 00:04:24,000
479
+ with the same data.
480
+
481
+ 121
482
+ 00:04:24,000 --> 00:04:25,000
483
+ So it doesn't make sense, right?
484
+
485
+ 122
486
+ 00:04:25,000 --> 00:04:27,000
487
+ And that's why it uses a string constant pool.
488
+
489
+ 123
490
+ 00:04:27,000 --> 00:04:30,000
491
+ Now, my question to you is, what is happening here?
492
+
493
+ 124
494
+ 00:04:30,000 --> 00:04:33,000
495
+ Now when I say you can't change the data,
496
+
497
+ 125
498
+ 00:04:33,000 --> 00:04:36,000
499
+ that means you cannot simply update this particular
500
+
501
+ 126
502
+ 00:04:36,000 --> 00:04:37,000
503
+ navin by Navin Reddy?
504
+
505
+ 127
506
+ 00:04:37,000 --> 00:04:40,000
507
+ No, that's not happening, navin is still there.
508
+
509
+ 128
510
+ 00:04:40,000 --> 00:04:42,000
511
+ It's a constant. You can't change this.
512
+
513
+ 129
514
+ 00:04:42,000 --> 00:04:43,000
515
+ Now on line number 9,
516
+
517
+ 130
518
+ 00:04:43,000 --> 00:04:47,000
519
+ what is happening is it is creating a new object
520
+
521
+ 131
522
+ 00:04:47,000 --> 00:04:51,000
523
+ which will have a data which is navin reddy,
524
+
525
+ 132
526
+ 00:04:51,000 --> 00:04:53,000
527
+ let's say it has the address, which is 105.
528
+
529
+ 133
530
+ 00:04:53,000 --> 00:04:54,000
531
+ So on line number 9,
532
+
533
+ 134
534
+ 00:04:54,000 --> 00:04:58,000
535
+ basically what you're doing is you are changing this address
536
+
537
+ 135
538
+ 00:04:58,000 --> 00:05:01,000
539
+ from 101 to 105.
540
+
541
+ 136
542
+ 00:05:01,000 --> 00:05:04,000
543
+ You are just changing the address.
544
+
545
+ 137
546
+ 00:05:04,000 --> 00:05:06,000
547
+ You're not changing the actual data.
548
+
549
+ 138
550
+ 00:05:06,000 --> 00:05:09,000
551
+ You are basically creating a new object.
552
+
553
+ 139
554
+ 00:05:09,000 --> 00:05:09,000
555
+ Okay?
556
+
557
+ 140
558
+ 00:05:09,000 --> 00:05:12,000
559
+ Now, you might be thinking what will happen to navin here?
560
+
561
+ 141
562
+ 00:05:12,000 --> 00:05:13,000
563
+ The thing is,
564
+
565
+ 142
566
+ 00:05:13,000 --> 00:05:16,000
567
+ now this particular object is eligible
568
+
569
+ 143
570
+ 00:05:16,000 --> 00:05:17,000
571
+ for garbage collection.
572
+
573
+ 144
574
+ 00:05:17,000 --> 00:05:19,000
575
+ It'll be removed after some time,
576
+
577
+ 145
578
+ 00:05:19,000 --> 00:05:21,000
579
+ just to get some memory back.
580
+
581
+ 146
582
+ 00:05:21,000 --> 00:05:22,000
583
+ Okay?
584
+
585
+ 147
586
+ 00:05:22,000 --> 00:05:24,000
587
+ So point to remember is once you create this object,
588
+
589
+ 148
590
+ 00:05:24,000 --> 00:05:25,000
591
+ you can't change it.
592
+
593
+ 149
594
+ 00:05:25,000 --> 00:05:28,000
595
+ And that's where we have some terms to remember.
596
+
597
+ 150
598
+ 00:05:28,000 --> 00:05:29,000
599
+ And the terms are,
600
+
601
+ 151
602
+ 00:05:29,000 --> 00:05:33,000
603
+ so there's a concept of mutable strings
604
+
605
+ 152
606
+ 00:05:33,000 --> 00:05:35,000
607
+ and immutable string.
608
+
609
+ 153
610
+ 00:05:35,000 --> 00:05:36,000
611
+ Now, what is mutable means?
612
+
613
+ 154
614
+ 00:05:36,000 --> 00:05:40,000
615
+ Mutable means change something which can be changed.
616
+
617
+ 155
618
+ 00:05:40,000 --> 00:05:43,000
619
+ And immutable means unchanged or you cannot change it.
620
+
621
+ 156
622
+ 00:05:43,000 --> 00:05:46,000
623
+ So basically, by default strings are immutable.
624
+
625
+ 157
626
+ 00:05:46,000 --> 00:05:48,000
627
+ Once you create the object, you can't change it.
628
+
629
+ 158
630
+ 00:05:48,000 --> 00:05:49,000
631
+ And that's very important remember,
632
+
633
+ 159
634
+ 00:05:49,000 --> 00:05:51,000
635
+ it's immutable string, okay?
636
+
637
+ 160
638
+ 00:05:51,000 --> 00:05:53,000
639
+ So whatever data you're creating here is immutable.
640
+
641
+ 161
642
+ 00:05:53,000 --> 00:05:55,000
643
+ But what if you want mutable string?
644
+
645
+ 162
646
+ 00:05:55,000 --> 00:05:58,000
647
+ And that's why we have two different classes in Java to use.
648
+
649
+ 163
650
+ 00:05:58,000 --> 00:06:00,000
651
+ Instead of using string,
652
+
653
+ 164
654
+ 00:06:00,000 --> 00:06:04,000
655
+ you can use something called a string buffer
656
+
657
+ 165
658
+ 00:06:04,000 --> 00:06:07,000
659
+ or a string builder.
660
+
661
+ 166
662
+ 00:06:07,000 --> 00:06:09,000
663
+ Now, both are very similar with one difference
664
+
665
+ 167
666
+ 00:06:09,000 --> 00:06:10,000
667
+ that defense we'll discuss later,
668
+
669
+ 168
670
+ 00:06:10,000 --> 00:06:14,000
671
+ but they both are similar and they both provide you a way
672
+
673
+ 169
674
+ 00:06:14,000 --> 00:06:18,000
675
+ to implement a immutable string.
676
+
677
+ 170
678
+ 00:06:18,000 --> 00:06:18,000
679
+ Okay?
680
+
681
+ 171
682
+ 00:06:18,000 --> 00:06:19,000
683
+ Now, how do we do that?
684
+
685
+ 172
686
+ 00:06:19,000 --> 00:06:22,000
687
+ That we'll see in the upcoming videos.
688
+
02 - Core Java/039 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/040 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/040 StringBuffer and StringBuilder_en.srt ADDED
@@ -0,0 +1,620 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (soft chimes)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: In this video, we'll work with string buffer.
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:07,000
11
+ So, what we have is we have a string anvil
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:09,000
15
+ and we have work with it, right?
16
+
17
+ 5
18
+ 00:00:09,000 --> 00:00:11,000
19
+ So I'll do is remove everything
20
+
21
+ 6
22
+ 00:00:11,000 --> 00:00:13,000
23
+ and let's work with string buffer.
24
+
25
+ 7
26
+ 00:00:13,000 --> 00:00:15,000
27
+ So I'll say string buffer
28
+
29
+ 8
30
+ 00:00:15,000 --> 00:00:16,000
31
+ and lets create a reference call it
32
+
33
+ 9
34
+ 00:00:16,000 --> 00:00:19,000
35
+ equal to new... string buffer
36
+
37
+ 10
38
+ 00:00:19,000 --> 00:00:21,000
39
+ so when we talk about string buffer
40
+
41
+ 11
42
+ 00:00:21,000 --> 00:00:22,000
43
+ of course in this string buffer, you will have a string
44
+
45
+ 12
46
+ 00:00:22,000 --> 00:00:25,000
47
+ and if which is actually mutable
48
+
49
+ 13
50
+ 00:00:25,000 --> 00:00:26,000
51
+ you can change it...
52
+
53
+ 14
54
+ 00:00:26,000 --> 00:00:27,000
55
+ now to make it more efficient
56
+
57
+ 15
58
+ 00:00:27,000 --> 00:00:28,000
59
+ you know what string buffer does?
60
+
61
+ 16
62
+ 00:00:28,000 --> 00:00:31,000
63
+ String buffer will give you a "buffer size".. okay?
64
+
65
+ 17
66
+ 00:00:31,000 --> 00:00:33,000
67
+ Which is of 16 bytes
68
+
69
+ 18
70
+ 00:00:33,000 --> 00:00:34,000
71
+ so I can. I can just try to print that first
72
+
73
+ 19
74
+ 00:00:34,000 --> 00:00:36,000
75
+ I will say sb. 'dot'
76
+
77
+ 20
78
+ 00:00:36,000 --> 00:00:39,000
79
+ so we can know the capacity of the string buffer
80
+
81
+ 21
82
+ 00:00:39,000 --> 00:00:41,000
83
+ even if its empty, it will give a capacity
84
+
85
+ 22
86
+ 00:00:41,000 --> 00:00:43,000
87
+ of 16 characters and you got it there .
88
+
89
+ 23
90
+ 00:00:43,000 --> 00:00:46,000
91
+ In fact, you can also provide some initial string here,..
92
+
93
+ 24
94
+ 00:00:46,000 --> 00:00:48,000
95
+ So let's say.. uhh... if I say
96
+
97
+ 25
98
+ 00:00:48,000 --> 00:00:48,000
99
+ "Navin" here
100
+
101
+ 26
102
+ 00:00:48,000 --> 00:00:51,000
103
+ now Navin is a 5 charters right? This is how
104
+
105
+ 27
106
+ 00:00:51,000 --> 00:00:53,000
107
+ you basically create a string buffer.. in bracket
108
+
109
+ 28
110
+ 00:00:53,000 --> 00:00:54,000
111
+ you will mention the string
112
+
113
+ 29
114
+ 00:00:54,000 --> 00:00:56,000
115
+ so, it will create a string buffer object
116
+
117
+ 30
118
+ 00:00:56,000 --> 00:00:59,000
119
+ and the beauty is you can change this data.
120
+
121
+ 31
122
+ 00:00:59,000 --> 00:01:02,000
123
+ Okay.. now the thing is..uhh.. if you talk about
124
+
125
+ 32
126
+ 00:01:02,000 --> 00:01:03,000
127
+ capacity what it will be?..
128
+
129
+ 33
130
+ 00:01:03,000 --> 00:01:06,000
131
+ So capacity is..it should be still 16 right?
132
+
133
+ 34
134
+ 00:01:06,000 --> 00:01:07,000
135
+ No. It actually changes
136
+
137
+ 35
138
+ 00:01:07,000 --> 00:01:10,000
139
+ if you can see.. the capacity will become 21.
140
+
141
+ 36
142
+ 00:01:10,000 --> 00:01:12,000
143
+ It's because.. it will store my name and it
144
+
145
+ 37
146
+ 00:01:12,000 --> 00:01:16,000
147
+ will also give me a 16 space extra.
148
+
149
+ 38
150
+ 00:01:16,000 --> 00:01:18,000
151
+ Now why it gives me that space is because..
152
+
153
+ 39
154
+ 00:01:18,000 --> 00:01:21,000
155
+ Every time we'll change data, and if it consumes
156
+
157
+ 40
158
+ 00:01:21,000 --> 00:01:24,000
159
+ a continuous memory location inside your heap memory
160
+
161
+ 41
162
+ 00:01:24,000 --> 00:01:26,000
163
+ and what if there's no continuous location next
164
+
165
+ 42
166
+ 00:01:26,000 --> 00:01:28,000
167
+ (fumbles).. I mean Th.. what if there is no location
168
+
169
+ 43
170
+ 00:01:28,000 --> 00:01:30,000
171
+ available. There's no space available.
172
+
173
+ 44
174
+ 00:01:30,000 --> 00:01:32,000
175
+ In that case, it has to relocate. So to
176
+
177
+ 45
178
+ 00:01:32,000 --> 00:01:34,000
179
+ reduce the relo.. relocation of the string
180
+
181
+ 46
182
+ 00:01:34,000 --> 00:01:37,000
183
+ it gives you a buffer. Okay.
184
+
185
+ 47
186
+ 00:01:37,000 --> 00:01:40,000
187
+ So that's the capacity and now we know how it works.
188
+
189
+ 48
190
+ 00:01:40,000 --> 00:01:42,000
191
+ We can also print the length of the string and we can
192
+
193
+ 49
194
+ 00:01:42,000 --> 00:01:45,000
195
+ say... sb.length. And length is available in
196
+
197
+ 50
198
+ 00:01:45,000 --> 00:01:48,000
199
+ normal string as well. So if I compile
200
+
201
+ 51
202
+ 00:01:48,000 --> 00:01:50,000
203
+ and run, you can see the length is 5
204
+
205
+ 52
206
+ 00:01:50,000 --> 00:01:52,000
207
+ so, length and capacities are 2 different things.
208
+
209
+ 53
210
+ 00:01:52,000 --> 00:01:56,000
211
+ Okay, now can I append data?
212
+
213
+ 54
214
+ 00:01:56,000 --> 00:01:58,000
215
+ See, the ultimate thing was.. can I change
216
+
217
+ 55
218
+ 00:01:58,000 --> 00:02:00,000
219
+ my data, which is "Navin" in this case.
220
+
221
+ 56
222
+ 00:02:00,000 --> 00:02:03,000
223
+ The beauty is string buffer will give you
224
+
225
+ 57
226
+ 00:02:03,000 --> 00:02:05,000
227
+ a lot of different methods to do that..
228
+
229
+ 58
230
+ 00:02:05,000 --> 00:02:06,000
231
+ You can see we have a metho...method called
232
+
233
+ 59
234
+ 00:02:06,000 --> 00:02:08,000
235
+ append.. so you can use append
236
+
237
+ 60
238
+ 00:02:08,000 --> 00:02:10,000
239
+ and you can append a data which you want to..
240
+
241
+ 61
242
+ 00:02:10,000 --> 00:02:13,000
243
+ So lets say I want to append.. "Reddy" here,
244
+
245
+ 62
246
+ 00:02:13,000 --> 00:02:14,000
247
+ and of course I want to give a space
248
+
249
+ 63
250
+ 00:02:14,000 --> 00:02:17,000
251
+ between "Navin" uhh.. "Navin" and "Reddy".
252
+
253
+ 64
254
+ 00:02:17,000 --> 00:02:19,000
255
+ So you can append and you can print the data...
256
+
257
+ 65
258
+ 00:02:19,000 --> 00:02:21,000
259
+ So you can print 'sb' as it is..
260
+
261
+ 66
262
+ 00:02:21,000 --> 00:02:23,000
263
+ Let's.. uh. First we have to compile the
264
+
265
+ 67
266
+ 00:02:23,000 --> 00:02:25,000
267
+ code.. Run. And you can see the code
268
+
269
+ 68
270
+ 00:02:25,000 --> 00:02:27,000
271
+ "Navin" "Reddy" it wo.. that works.
272
+
273
+ 69
274
+ 00:02:27,000 --> 00:02:30,000
275
+ Next, what if you want to assign string buffer
276
+
277
+ 70
278
+ 00:02:30,000 --> 00:02:32,000
279
+ data to string is example if I do that..uh,
280
+
281
+ 71
282
+ 00:02:32,000 --> 00:02:35,000
283
+ you can see.. it will... give you a log.
284
+
285
+ 72
286
+ 00:02:35,000 --> 00:02:37,000
287
+ It says, type mismatch: cannot convert from
288
+
289
+ 73
290
+ 00:02:37,000 --> 00:02:39,000
291
+ string buffer to String.. oo of course
292
+
293
+ 74
294
+ 00:02:39,000 --> 00:02:42,000
295
+ right? HTI is of type string, so in that case
296
+
297
+ 75
298
+ 00:02:42,000 --> 00:02:45,000
299
+ you can get the string back.. do we have
300
+
301
+ 76
302
+ 00:02:45,000 --> 00:02:46,000
303
+ a method for it?
304
+
305
+ 77
306
+ 00:02:46,000 --> 00:02:48,000
307
+ Lets see...yes we do have two string
308
+
309
+ 78
310
+ 00:02:48,000 --> 00:02:49,000
311
+ we can use that
312
+
313
+ 79
314
+ 00:02:49,000 --> 00:02:52,000
315
+ I think that's the only method we can use...
316
+
317
+ 80
318
+ 00:02:52,000 --> 00:02:53,000
319
+ Yup, so let's see those two string.
320
+
321
+ 81
322
+ 00:02:53,000 --> 00:02:56,000
323
+ So, basically you can use two string to convert
324
+
325
+ 82
326
+ 00:02:56,000 --> 00:02:58,000
327
+ the.. . string buffer data. I mean it will
328
+
329
+ 83
330
+ 00:02:58,000 --> 00:03:01,000
331
+ get the string format, it was stored in HTR
332
+
333
+ 84
334
+ 00:03:01,000 --> 00:03:03,000
335
+ and you can print it.
336
+
337
+ 85
338
+ 00:03:03,000 --> 00:03:05,000
339
+ Okay. We can use that... what else we can do
340
+
341
+ 86
342
+ 00:03:05,000 --> 00:03:06,000
343
+ with string buffer?
344
+
345
+ 87
346
+ 00:03:06,000 --> 00:03:09,000
347
+ If I come back here if I say sb'dot',
348
+
349
+ 88
350
+ 00:03:09,000 --> 00:03:11,000
351
+ you can see we have so many methods here.
352
+
353
+ 89
354
+ 00:03:11,000 --> 00:03:13,000
355
+ Okay, so we have append.. we have chars, it will give you
356
+
357
+ 90
358
+ 00:03:13,000 --> 00:03:17,000
359
+ a character... we have done that
360
+
361
+ 91
362
+ 00:03:17,000 --> 00:03:19,000
363
+ okay, so we can also delete something, we can
364
+
365
+ 92
366
+ 00:03:19,000 --> 00:03:20,000
367
+ delete a character at an index. So next
368
+
369
+ 93
370
+ 00:03:20,000 --> 00:03:23,000
371
+ I will delete a character at location "2".
372
+
373
+ 94
374
+ 00:03:23,000 --> 00:03:27,000
375
+ If you try to delete that data..compile and.. run.
376
+
377
+ 95
378
+ 00:03:27,000 --> 00:03:29,000
379
+ You can see we got, oh! Something is missing
380
+
381
+ 96
382
+ 00:03:29,000 --> 00:03:30,000
383
+ the way is missing there.
384
+
385
+ 97
386
+ 00:03:30,000 --> 00:03:33,000
387
+ Because that is at index number "2"
388
+
389
+ 98
390
+ 00:03:33,000 --> 00:03:35,000
391
+ okay, so the idea is we basically we can change it
392
+
393
+ 99
394
+ 00:03:35,000 --> 00:03:37,000
395
+ and you can experiment it a lot.
396
+
397
+ 100
398
+ 00:03:37,000 --> 00:03:41,000
399
+ You can try to use different methods, we can delete,
400
+
401
+ 101
402
+ 00:03:41,000 --> 00:03:43,000
403
+ we can insert also in between, lets say
404
+
405
+ 102
406
+ 00:03:43,000 --> 00:03:46,000
407
+ I want to insert .. uh. Java at the start,
408
+
409
+ 103
410
+ 00:03:46,000 --> 00:03:48,000
411
+ you can do that. So you can say insert
412
+
413
+ 104
414
+ 00:03:48,000 --> 00:03:49,000
415
+ you can mention the index value where you want
416
+
417
+ 105
418
+ 00:03:49,000 --> 00:03:52,000
419
+ to insert exact location, and the data that you
420
+
421
+ 106
422
+ 00:03:52,000 --> 00:03:54,000
423
+ ..which you want to insert. So I will say
424
+
425
+ 107
426
+ 00:03:54,000 --> 00:03:56,000
427
+ Java 'space', now what it will do is
428
+
429
+ 108
430
+ 00:03:56,000 --> 00:04:00,000
431
+ It will add Java at index 0, I mean that is start
432
+
433
+ 109
434
+ 00:04:00,000 --> 00:04:02,000
435
+ itself. So if I run, you can see it says Java..
436
+
437
+ 110
438
+ 00:04:02,000 --> 00:04:05,000
439
+ Of course you can add Java in between as well.
440
+
441
+ 111
442
+ 00:04:05,000 --> 00:04:08,000
443
+ Uh.. lets say I want to add.. after...
444
+
445
+ 112
446
+ 00:04:08,000 --> 00:04:10,000
447
+ 5th location I think... that should work.
448
+
449
+ 113
450
+ 00:04:10,000 --> 00:04:13,000
451
+ After this space it's 6, so let's try that..
452
+
453
+ 114
454
+ 00:04:13,000 --> 00:04:15,000
455
+ Compile Run. You can see its.. "Navin"
456
+
457
+ 115
458
+ 00:04:15,000 --> 00:04:17,000
459
+ "Java", "Reddy" so it works.
460
+
461
+ 116
462
+ 00:04:17,000 --> 00:04:20,000
463
+ Okay.. so, yeah that's how we can basically use insert
464
+
465
+ 117
466
+ 00:04:20,000 --> 00:04:22,000
467
+ we have more methods to explore and I would
468
+
469
+ 118
470
+ 00:04:22,000 --> 00:04:24,000
471
+ recommend you to do that. Can we just see
472
+
473
+ 119
474
+ 00:04:24,000 --> 00:04:26,000
475
+ one more.. We can also get the substring..
476
+
477
+ 120
478
+ 00:04:26,000 --> 00:04:27,000
479
+ Let's say if you have a very big string
480
+
481
+ 121
482
+ 00:04:27,000 --> 00:04:30,000
483
+ you can specify.. the starting point, ending point
484
+
485
+ 122
486
+ 00:04:30,000 --> 00:04:33,000
487
+ using substring. You can set the length as well.
488
+
489
+ 123
490
+ 00:04:33,000 --> 00:04:36,000
491
+ So If you set the length of the stream, let's
492
+
493
+ 124
494
+ 00:04:36,000 --> 00:04:38,000
495
+ say I want to set the length of "30".
496
+
497
+ 125
498
+ 00:04:38,000 --> 00:04:40,000
499
+ So, if you want to add your data and
500
+
501
+ 126
502
+ 00:04:40,000 --> 00:04:42,000
503
+ if you want to have a specific length..
504
+
505
+ 127
506
+ 00:04:42,000 --> 00:04:43,000
507
+ Which is 30 here.
508
+
509
+ 128
510
+ 00:04:43,000 --> 00:04:44,000
511
+ It will save the data which is whatever
512
+
513
+ 129
514
+ 00:04:44,000 --> 00:04:46,000
515
+ you have. "Navin" 20 will be stored and
516
+
517
+ 130
518
+ 00:04:46,000 --> 00:04:47,000
519
+ all the other values will be... will be
520
+
521
+ 131
522
+ 00:04:47,000 --> 00:04:49,000
523
+ null.. let's see. So after "Navin" Reddy" it will
524
+
525
+ 132
526
+ 00:04:49,000 --> 00:04:52,000
527
+ add some extra data here... okay.
528
+
529
+ 133
530
+ 00:04:52,000 --> 00:04:54,000
531
+ So that you can replace that later. Cool.. we
532
+
533
+ 134
534
+ 00:04:54,000 --> 00:04:57,000
535
+ can do that... we can also set a minimum or
536
+
537
+ 135
538
+ 00:04:57,000 --> 00:04:59,000
539
+ maximum data. I think there's minimum capacity
540
+
541
+ 136
542
+ 00:04:59,000 --> 00:05:02,000
543
+ method which we can use... I think the method
544
+
545
+ 137
546
+ 00:05:02,000 --> 00:05:05,000
547
+ name is "ensurecapacity", yeah okay.
548
+
549
+ 138
550
+ 00:05:05,000 --> 00:05:08,000
551
+ So we can, we can set the ensurecapacity to 100
552
+
553
+ 139
554
+ 00:05:08,000 --> 00:05:11,000
555
+ so it..minimum, minimum capacity will be 100.
556
+
557
+ 140
558
+ 00:05:11,000 --> 00:05:13,000
559
+ Okay um that's how you have different methods.
560
+
561
+ 141
562
+ 00:05:13,000 --> 00:05:15,000
563
+ Now what's the difference between string buffer and
564
+
565
+ 142
566
+ 00:05:15,000 --> 00:05:17,000
567
+ string builder. So as I mentioned we also have
568
+
569
+ 143
570
+ 00:05:17,000 --> 00:05:18,000
571
+ string builder right?..there's only one
572
+
573
+ 144
574
+ 00:05:18,000 --> 00:05:22,000
575
+ difference, string buffer is thread safe and
576
+
577
+ 145
578
+ 00:05:22,000 --> 00:05:23,000
579
+ string builder is not..
580
+
581
+ 146
582
+ 00:05:23,000 --> 00:05:25,000
583
+ Now what is thread safe means that we
584
+
585
+ 147
586
+ 00:05:25,000 --> 00:05:26,000
587
+ will understand once we talk about
588
+
589
+ 148
590
+ 00:05:26,000 --> 00:05:29,000
591
+ thread concept.. so that point also ..
592
+
593
+ 149
594
+ 00:05:29,000 --> 00:05:31,000
595
+ we'll talk about difference between string buffer
596
+
597
+ 150
598
+ 00:05:31,000 --> 00:05:33,000
599
+ and string builder, but what other methods
600
+
601
+ 151
602
+ 00:05:33,000 --> 00:05:35,000
603
+ you have in string buffer is almost
604
+
605
+ 152
606
+ 00:05:35,000 --> 00:05:37,000
607
+ the same as string builder. So if you
608
+
609
+ 153
610
+ 00:05:37,000 --> 00:05:39,000
611
+ know one.. you know the other one as well.
612
+
613
+ 154
614
+ 00:05:39,000 --> 00:05:41,000
615
+ Okay, so that's about string buffer and...
616
+
617
+ 155
618
+ 00:05:41,000 --> 00:05:43,000
619
+ Some of the methods of string.
620
+
02 - Core Java/041 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/041 Static Variable_en.srt ADDED
@@ -0,0 +1,700 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: In this video, we'll talk about static keyword.
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:08,000
11
+ From the start itself, when we have written the first code,
12
+
13
+ 4
14
+ 00:00:08,000 --> 00:00:10,000
15
+ we are looking at the static keyword,
16
+
17
+ 5
18
+ 00:00:10,000 --> 00:00:12,000
19
+ and the question still remains, right,
20
+
21
+ 6
22
+ 00:00:12,000 --> 00:00:14,000
23
+ what is the static?
24
+
25
+ 7
26
+ 00:00:14,000 --> 00:00:15,000
27
+ So we know what is method is,
28
+
29
+ 8
30
+ 00:00:15,000 --> 00:00:17,000
31
+ we know what is return type, we know what is class.
32
+
33
+ 9
34
+ 00:00:17,000 --> 00:00:21,000
35
+ But again, problem gets stuck here in static itself.
36
+
37
+ 10
38
+ 00:00:21,000 --> 00:00:23,000
39
+ Now to make you understand this, let's take an example here.
40
+
41
+ 11
42
+ 00:00:23,000 --> 00:00:26,000
43
+ So let's say we have an example of mobile phone,
44
+
45
+ 12
46
+ 00:00:26,000 --> 00:00:28,000
47
+ and every mobile phone has a brand.
48
+
49
+ 13
50
+ 00:00:28,000 --> 00:00:31,000
51
+ So brand will be string, so it's String brand,
52
+
53
+ 14
54
+ 00:00:32,000 --> 00:00:34,000
55
+ and we can have a default value for it.
56
+
57
+ 15
58
+ 00:00:34,000 --> 00:00:37,000
59
+ We can have int, which is price,
60
+
61
+ 16
62
+ 00:00:37,000 --> 00:00:42,000
63
+ and then String network, okay?
64
+
65
+ 17
66
+ 00:00:43,000 --> 00:00:46,000
67
+ And we can also make it for a specific brand as well,
68
+
69
+ 18
70
+ 00:00:46,000 --> 00:00:47,000
71
+ but let's keep it simple.
72
+
73
+ 19
74
+ 00:00:47,000 --> 00:00:49,000
75
+ Let's have a mobile phone, different brands,
76
+
77
+ 20
78
+ 00:00:49,000 --> 00:00:53,000
79
+ different price, different network, and we'll say name.
80
+
81
+ 21
82
+ 00:00:53,000 --> 00:00:56,000
83
+ Okay, now see name itself of a mobile phone changes, right?
84
+
85
+ 22
86
+ 00:00:56,000 --> 00:01:00,000
87
+ So we used to say normal phones, then we got smartphones,
88
+
89
+ 23
90
+ 00:01:00,000 --> 00:01:02,000
91
+ and now we have foldable phones, right?
92
+
93
+ 24
94
+ 00:01:02,000 --> 00:01:04,000
95
+ So we can have a different name to phones nowadays.
96
+
97
+ 25
98
+ 00:01:04,000 --> 00:01:06,000
99
+ Every phone is called a smartphone now
100
+
101
+ 26
102
+ 00:01:06,000 --> 00:01:08,000
103
+ because that's what we call it.
104
+
105
+ 27
106
+ 00:01:08,000 --> 00:01:09,000
107
+ Usually, we used to call it mobile,
108
+
109
+ 28
110
+ 00:01:09,000 --> 00:01:11,000
111
+ then we used to call it phone, right?
112
+
113
+ 29
114
+ 00:01:11,000 --> 00:01:13,000
115
+ So we have a name here as well.
116
+
117
+ 30
118
+ 00:01:13,000 --> 00:01:16,000
119
+ What do you call a mobile phone? So now it's a smartphone.
120
+
121
+ 31
122
+ 00:01:16,000 --> 00:01:18,000
123
+ Okay, so if you want to work with this mobile phone,
124
+
125
+ 32
126
+ 00:01:18,000 --> 00:01:19,000
127
+ of course, you have to create an object, right?
128
+
129
+ 33
130
+ 00:01:19,000 --> 00:01:21,000
131
+ So if I say Mobile obj,
132
+
133
+ 34
134
+ 00:01:21,000 --> 00:01:24,000
135
+ if I will say Mobile obj1 = new Mobile.
136
+
137
+ 35
138
+ 00:01:24,000 --> 00:01:26,000
139
+ And of course, every mobile will have
140
+
141
+ 36
142
+ 00:01:26,000 --> 00:01:27,000
143
+ a different parameter here.
144
+
145
+ 37
146
+ 00:01:27,000 --> 00:01:29,000
147
+ What I will do is I will just remove this network just
148
+
149
+ 38
150
+ 00:01:29,000 --> 00:01:32,000
151
+ to keep it simple, we just want three variables here,
152
+
153
+ 39
154
+ 00:01:32,000 --> 00:01:35,000
155
+ obj1.brand, I want to set the brand here.
156
+
157
+ 40
158
+ 00:01:35,000 --> 00:01:37,000
159
+ Let's say the brand is Apple
160
+
161
+ 41
162
+ 00:01:37,000 --> 00:01:39,000
163
+ since I'm using an Apple phone here.
164
+
165
+ 42
166
+ 00:01:39,000 --> 00:01:44,000
167
+ And then the price, let's say $1,500.
168
+
169
+ 43
170
+ 00:01:44,000 --> 00:01:46,000
171
+ And what else we have? We have a name.
172
+
173
+ 44
174
+ 00:01:46,000 --> 00:01:47,000
175
+ So what do you call a mobile phone?
176
+
177
+ 45
178
+ 00:01:47,000 --> 00:01:50,000
179
+ So currently, if we talk about Apple phones
180
+
181
+ 46
182
+ 00:01:50,000 --> 00:01:54,000
183
+ or any phones nowadays, we call them as a smartphone, okay?
184
+
185
+ 47
186
+ 00:01:54,000 --> 00:01:55,000
187
+ I know this variable doesn't make sense,
188
+
189
+ 48
190
+ 00:01:55,000 --> 00:01:57,000
191
+ but just for the example,
192
+
193
+ 49
194
+ 00:01:57,000 --> 00:02:00,000
195
+ I'm saying name = "SmartPhone", right?
196
+
197
+ 50
198
+ 00:02:00,000 --> 00:02:03,000
199
+ Now if you talk about this phone here,
200
+
201
+ 51
202
+ 00:02:03,000 --> 00:02:05,000
203
+ we have all these values, right?
204
+
205
+ 52
206
+ 00:02:05,000 --> 00:02:09,000
207
+ Now of course, if I create multiple objects,
208
+
209
+ 53
210
+ 00:02:09,000 --> 00:02:10,000
211
+ it should have a different value.
212
+
213
+ 54
214
+ 00:02:10,000 --> 00:02:11,000
215
+ Of course, every object is different,
216
+
217
+ 55
218
+ 00:02:11,000 --> 00:02:13,000
219
+ so we can have a different value to it.
220
+
221
+ 56
222
+ 00:02:13,000 --> 00:02:14,000
223
+ If I come back to Apple,
224
+
225
+ 57
226
+ 00:02:14,000 --> 00:02:17,000
227
+ let's say the next phone is of Samsung,
228
+
229
+ 58
230
+ 00:02:17,000 --> 00:02:20,000
231
+ and the price is let's say $1,700.
232
+
233
+ 59
234
+ 00:02:20,000 --> 00:02:24,000
235
+ And then we also call them as SmartPhone, okay?
236
+
237
+ 60
238
+ 00:02:24,000 --> 00:02:25,000
239
+ The only thing that we have to change it here
240
+
241
+ 61
242
+ 00:02:25,000 --> 00:02:27,000
243
+ as well, obj2, obj2,
244
+
245
+ 62
246
+ 00:02:27,000 --> 00:02:30,000
247
+ and then I can print the values as well.
248
+
249
+ 63
250
+ 00:02:30,000 --> 00:02:31,000
251
+ You know what I will do?
252
+
253
+ 64
254
+ 00:02:31,000 --> 00:02:33,000
255
+ I will just create a method which will print everything.
256
+
257
+ 65
258
+ 00:02:33,000 --> 00:02:34,000
259
+ I will say public void show.
260
+
261
+ 66
262
+ 00:02:34,000 --> 00:02:36,000
263
+ It should print all the details here.
264
+
265
+ 67
266
+ 00:02:36,000 --> 00:02:39,000
267
+ So it should print brand so that I don't have
268
+
269
+ 68
270
+ 00:02:39,000 --> 00:02:41,000
271
+ to print that every time,
272
+
273
+ 69
274
+ 00:02:41,000 --> 00:02:45,000
275
+ and I will say price, and I will print name as well.
276
+
277
+ 70
278
+ 00:02:45,000 --> 00:02:45,000
279
+ Now by doing this,
280
+
281
+ 71
282
+ 00:02:45,000 --> 00:02:49,000
283
+ what I'm doing is instead of printing it here every value,
284
+
285
+ 72
286
+ 00:02:49,000 --> 00:02:53,000
287
+ I can simply call obj1.show do show and obj2.show.
288
+
289
+ 73
290
+ 00:02:53,000 --> 00:02:56,000
291
+ So it'll print its own value, not other values.
292
+
293
+ 74
294
+ 00:02:56,000 --> 00:03:00,000
295
+ And if I come back here, compile and run,
296
+
297
+ 75
298
+ 00:03:00,000 --> 00:03:01,000
299
+ you can see we got the values, right?
300
+
301
+ 76
302
+ 00:03:01,000 --> 00:03:02,000
303
+ Nothing complex here.
304
+
305
+ 77
306
+ 00:03:02,000 --> 00:03:05,000
307
+ The thing is if we talk about these variables here,
308
+
309
+ 78
310
+ 00:03:05,000 --> 00:03:07,000
311
+ they are called instance variable, right?
312
+
313
+ 79
314
+ 00:03:07,000 --> 00:03:08,000
315
+ Now if you create a variable inside a method,
316
+
317
+ 80
318
+ 00:03:08,000 --> 00:03:10,000
319
+ that's a local variable.
320
+
321
+ 81
322
+ 00:03:10,000 --> 00:03:12,000
323
+ But this are your instance variable,
324
+
325
+ 82
326
+ 00:03:12,000 --> 00:03:14,000
327
+ and every variable
328
+
329
+ 83
330
+ 00:03:14,000 --> 00:03:16,000
331
+ for a particular object is different, right?
332
+
333
+ 84
334
+ 00:03:16,000 --> 00:03:17,000
335
+ The value will be different.
336
+
337
+ 85
338
+ 00:03:17,000 --> 00:03:21,000
339
+ Now what I want is I want to have the name
340
+
341
+ 86
342
+ 00:03:21,000 --> 00:03:23,000
343
+ to be same for all the objects.
344
+
345
+ 87
346
+ 00:03:23,000 --> 00:03:25,000
347
+ See, because what is happening is in your memory,
348
+
349
+ 88
350
+ 00:03:25,000 --> 00:03:27,000
351
+ so let's say we have a JVM, a big JVM,
352
+
353
+ 89
354
+ 00:03:27,000 --> 00:03:30,000
355
+ and inside this, you have a stack
356
+
357
+ 90
358
+ 00:03:30,000 --> 00:03:34,000
359
+ where you have all the reference and locations and address,
360
+
361
+ 91
362
+ 00:03:34,000 --> 00:03:35,000
363
+ and then you have a heap memory.
364
+
365
+ 92
366
+ 00:03:35,000 --> 00:03:38,000
367
+ So in total, you can see we got two objects, right?
368
+
369
+ 93
370
+ 00:03:38,000 --> 00:03:43,000
371
+ One with Mobile obj1 and one is obj2,
372
+
373
+ 94
374
+ 00:03:43,000 --> 00:03:45,000
375
+ and then of course, they have the address as well.
376
+
377
+ 95
378
+ 00:03:45,000 --> 00:03:47,000
379
+ So this is 101, 103.
380
+
381
+ 96
382
+ 00:03:47,000 --> 00:03:51,000
383
+ And of course, this will be 101, 103,
384
+
385
+ 97
386
+ 00:03:51,000 --> 00:03:52,000
387
+ and you will be referring that, right?
388
+
389
+ 98
390
+ 00:03:52,000 --> 00:03:55,000
391
+ So this is for that here, this is for that here.
392
+
393
+ 99
394
+ 00:03:55,000 --> 00:03:57,000
395
+ Now that's how we can basically use it,
396
+
397
+ 100
398
+ 00:03:57,000 --> 00:03:59,000
399
+ and every object will have a different value.
400
+
401
+ 101
402
+ 00:03:59,000 --> 00:04:01,000
403
+ But what if I want
404
+
405
+ 102
406
+ 00:04:01,000 --> 00:04:03,000
407
+ to have a common value for all the objects?
408
+
409
+ 103
410
+ 00:04:03,000 --> 00:04:06,000
411
+ The problem with this is if I want to make sure
412
+
413
+ 104
414
+ 00:04:06,000 --> 00:04:08,000
415
+ that the name variable should not be a part of the object,
416
+
417
+ 105
418
+ 00:04:08,000 --> 00:04:09,000
419
+ because that's an instance variable.
420
+
421
+ 106
422
+ 00:04:09,000 --> 00:04:11,000
423
+ Now it will have a part of the object,
424
+
425
+ 107
426
+ 00:04:11,000 --> 00:04:13,000
427
+ and every object will have a different value.
428
+
429
+ 108
430
+ 00:04:13,000 --> 00:04:17,000
431
+ I want this name to be common for all. How do I do that?
432
+
433
+ 109
434
+ 00:04:17,000 --> 00:04:22,000
435
+ Now if you make this variable as static, now by doing that,
436
+
437
+ 110
438
+ 00:04:22,000 --> 00:04:26,000
439
+ what we are doing is we are making this name variable common
440
+
441
+ 111
442
+ 00:04:26,000 --> 00:04:28,000
443
+ to all the object.
444
+
445
+ 112
446
+ 00:04:28,000 --> 00:04:31,000
447
+ What I mean by that is, let's say after sometime,
448
+
449
+ 113
450
+ 00:04:31,000 --> 00:04:34,000
451
+ if I say obj1.name.
452
+
453
+ 114
454
+ 00:04:34,000 --> 00:04:37,000
455
+ If I change the name to let's say a Phone here,
456
+
457
+ 115
458
+ 00:04:37,000 --> 00:04:39,000
459
+ just a Phone, not a SmartPhone anymore.
460
+
461
+ 116
462
+ 00:04:39,000 --> 00:04:42,000
463
+ If you make this as a Phone and if you see the values,
464
+
465
+ 117
466
+ 00:04:42,000 --> 00:04:46,000
467
+ it will affect all the objects.
468
+
469
+ 118
470
+ 00:04:46,000 --> 00:04:49,000
471
+ You can see we are trying to change the name of obj1,
472
+
473
+ 119
474
+ 00:04:49,000 --> 00:04:54,000
475
+ but we are actually changing the name of obj2 as well.
476
+
477
+ 120
478
+ 00:04:54,000 --> 00:04:56,000
479
+ You can see this is also Phone now.
480
+
481
+ 121
482
+ 00:04:56,000 --> 00:04:59,000
483
+ The reason is the static variable is actually shared
484
+
485
+ 122
486
+ 00:04:59,000 --> 00:05:01,000
487
+ by all the objects.
488
+
489
+ 123
490
+ 00:05:01,000 --> 00:05:03,000
491
+ So basically, we'll not be having individual static variable
492
+
493
+ 124
494
+ 00:05:03,000 --> 00:05:05,000
495
+ for every object.
496
+
497
+ 125
498
+ 00:05:05,000 --> 00:05:06,000
499
+ We have a common variable,
500
+
501
+ 126
502
+ 00:05:06,000 --> 00:05:08,000
503
+ which will be used by all the objects.
504
+
505
+ 127
506
+ 00:05:08,000 --> 00:05:11,000
507
+ Imagine there is a common variable here, name,
508
+
509
+ 128
510
+ 00:05:11,000 --> 00:05:14,000
511
+ and all the objects will be referring to the same variable.
512
+
513
+ 129
514
+ 00:05:14,000 --> 00:05:16,000
515
+ So if you change the value for this,
516
+
517
+ 130
518
+ 00:05:16,000 --> 00:05:19,000
519
+ it will affect all the objects, okay?
520
+
521
+ 131
522
+ 00:05:19,000 --> 00:05:22,000
523
+ Now this is why we use static.
524
+
525
+ 132
526
+ 00:05:22,000 --> 00:05:24,000
527
+ Now the beauty is see,
528
+
529
+ 133
530
+ 00:05:24,000 --> 00:05:26,000
531
+ why we have to refer brand with obj1,
532
+
533
+ 134
534
+ 00:05:26,000 --> 00:05:27,000
535
+ price with obj1 is
536
+
537
+ 135
538
+ 00:05:27,000 --> 00:05:31,000
539
+ because every object will have a different value for it.
540
+
541
+ 136
542
+ 00:05:31,000 --> 00:05:34,000
543
+ Now don't you think name is a static variable,
544
+
545
+ 137
546
+ 00:05:34,000 --> 00:05:37,000
547
+ and it will be common for all the objects?
548
+
549
+ 138
550
+ 00:05:37,000 --> 00:05:40,000
551
+ And that's why you can actually call name
552
+
553
+ 139
554
+ 00:05:40,000 --> 00:05:43,000
555
+ with the help of a class name itself.
556
+
557
+ 140
558
+ 00:05:43,000 --> 00:05:45,000
559
+ You can simply say Mobile.name.
560
+
561
+ 141
562
+ 00:05:45,000 --> 00:05:47,000
563
+ So static variables should be called
564
+
565
+ 142
566
+ 00:05:47,000 --> 00:05:50,000
567
+ with their class name, not with objects.
568
+
569
+ 143
570
+ 00:05:50,000 --> 00:05:53,000
571
+ You can call with objects, but avoid it.
572
+
573
+ 144
574
+ 00:05:53,000 --> 00:05:55,000
575
+ And that's why you can see it gives you warning as well.
576
+
577
+ 145
578
+ 00:05:55,000 --> 00:05:58,000
579
+ It says, "The static field Mobile.name should be accessed
580
+
581
+ 146
582
+ 00:05:58,000 --> 00:06:03,000
583
+ in a static way," which is using the class name,
584
+
585
+ 147
586
+ 00:06:03,000 --> 00:06:05,000
587
+ which is mobile, okay?
588
+
589
+ 148
590
+ 00:06:05,000 --> 00:06:06,000
591
+ So the point
592
+
593
+ 149
594
+ 00:06:06,000 --> 00:06:09,000
595
+ to remember here is static variables are actually shared
596
+
597
+ 150
598
+ 00:06:09,000 --> 00:06:11,000
599
+ by different objects,
600
+
601
+ 151
602
+ 00:06:11,000 --> 00:06:13,000
603
+ and if you want to refer to a static variable,
604
+
605
+ 152
606
+ 00:06:13,000 --> 00:06:14,000
607
+ you can use a class name.
608
+
609
+ 153
610
+ 00:06:14,000 --> 00:06:17,000
611
+ So there's a different area in your JVM
612
+
613
+ 154
614
+ 00:06:17,000 --> 00:06:19,000
615
+ where you have all the static variables.
616
+
617
+ 155
618
+ 00:06:19,000 --> 00:06:22,000
619
+ And here as well, I should say Mobile.
620
+
621
+ 156
622
+ 00:06:22,000 --> 00:06:24,000
623
+ Now the thing is in non-static methods,
624
+
625
+ 157
626
+ 00:06:24,000 --> 00:06:26,000
627
+ you can use static variables.
628
+
629
+ 158
630
+ 00:06:26,000 --> 00:06:30,000
631
+ There's no harm, okay? And that's a point to remember.
632
+
633
+ 159
634
+ 00:06:30,000 --> 00:06:31,000
635
+ In the next video,
636
+
637
+ 160
638
+ 00:06:31,000 --> 00:06:33,000
639
+ we'll talk about what if you create a static method?
640
+
641
+ 161
642
+ 00:06:33,000 --> 00:06:35,000
643
+ Yes, we can do that. We can create static method.
644
+
645
+ 162
646
+ 00:06:35,000 --> 00:06:38,000
647
+ And the question is, can I use instance variables there?
648
+
649
+ 163
650
+ 00:06:38,000 --> 00:06:40,000
651
+ Okay, we'll see that in the next video.
652
+
653
+ 164
654
+ 00:06:40,000 --> 00:06:44,000
655
+ But here, we talked about what is a static keyword.
656
+
657
+ 165
658
+ 00:06:44,000 --> 00:06:47,000
659
+ So static keyword means you are making something
660
+
661
+ 166
662
+ 00:06:47,000 --> 00:06:49,000
663
+ as a class member, not a object member.
664
+
665
+ 167
666
+ 00:06:49,000 --> 00:06:52,000
667
+ So static, this name here belongs to a class,
668
+
669
+ 168
670
+ 00:06:52,000 --> 00:06:53,000
671
+ not to the object,
672
+
673
+ 169
674
+ 00:06:53,000 --> 00:06:55,000
675
+ and that's why you were able to use this
676
+
677
+ 170
678
+ 00:06:55,000 --> 00:06:58,000
679
+ with the help of a class name, okay?
680
+
681
+ 171
682
+ 00:06:58,000 --> 00:07:00,000
683
+ And then you're saving memory as well
684
+
685
+ 172
686
+ 00:07:00,000 --> 00:07:03,000
687
+ because not every object will have their own value for it
688
+
689
+ 173
690
+ 00:07:03,000 --> 00:07:05,000
691
+ or their own copy for it.
692
+
693
+ 174
694
+ 00:07:05,000 --> 00:07:06,000
695
+ So that's about static variable.
696
+
697
+ 175
698
+ 00:07:06,000 --> 00:07:09,000
699
+ In the next video, we'll talk about static methods.
700
+
02 - Core Java/042 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/042 Static method_en.srt ADDED
@@ -0,0 +1,508 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:03,000 --> 00:00:05,000
3
+ -: Now once we talked about static variable,
4
+
5
+ 2
6
+ 00:00:05,000 --> 00:00:07,000
7
+ it's time to talk about static methods.
8
+
9
+ 3
10
+ 00:00:07,000 --> 00:00:08,000
11
+ Now what I will do is
12
+
13
+ 4
14
+ 00:00:08,000 --> 00:00:11,000
15
+ I will just try to remove all this content from here
16
+
17
+ 5
18
+ 00:00:11,000 --> 00:00:13,000
19
+ just to keep it simple
20
+
21
+ 6
22
+ 00:00:13,000 --> 00:00:16,000
23
+ and let's make a static method.
24
+
25
+ 7
26
+ 00:00:16,000 --> 00:00:17,000
27
+ Now, the method which we have here show
28
+
29
+ 8
30
+ 00:00:17,000 --> 00:00:19,000
31
+ is not a static method, right?
32
+
33
+ 9
34
+ 00:00:19,000 --> 00:00:20,000
35
+ It's a instance method,
36
+
37
+ 10
38
+ 00:00:20,000 --> 00:00:23,000
39
+ is because we have not mentioned a static keyword.
40
+
41
+ 11
42
+ 00:00:23,000 --> 00:00:27,000
43
+ Now, whenever you want to work with a non-static method,
44
+
45
+ 12
46
+ 00:00:27,000 --> 00:00:29,000
47
+ you need to create an object of it.
48
+
49
+ 13
50
+ 00:00:29,000 --> 00:00:30,000
51
+ Of course, if you want to call,
52
+
53
+ 14
54
+ 00:00:30,000 --> 00:00:33,000
55
+ you have to create object of mobile.
56
+
57
+ 15
58
+ 00:00:33,000 --> 00:00:36,000
59
+ In fact, you know, actually we need those objects here
60
+
61
+ 16
62
+ 00:00:36,000 --> 00:00:40,000
63
+ and let's keep it here just to use it.
64
+
65
+ 17
66
+ 00:00:40,000 --> 00:00:42,000
67
+ Now let me create a simple static method.
68
+
69
+ 18
70
+ 00:00:42,000 --> 00:00:47,000
71
+ So I will say public static void show1.
72
+
73
+ 19
74
+ 00:00:48,000 --> 00:00:49,000
75
+ Again, if you can see,
76
+
77
+ 20
78
+ 00:00:49,000 --> 00:00:52,000
79
+ I'm using a different method name just to differentiate it.
80
+
81
+ 21
82
+ 00:00:52,000 --> 00:00:54,000
83
+ And here, if I try to,
84
+
85
+ 22
86
+ 00:00:54,000 --> 00:00:58,000
87
+ first of all, I will just print in static method.
88
+
89
+ 23
90
+ 00:00:59,000 --> 00:01:01,000
91
+ Now, how do we call the static method?
92
+
93
+ 24
94
+ 00:01:01,000 --> 00:01:04,000
95
+ To call show, we have to get object, right?
96
+
97
+ 25
98
+ 00:01:04,000 --> 00:01:08,000
99
+ You can't simply come back here and say, mobile.show,
100
+
101
+ 26
102
+ 00:01:08,000 --> 00:01:09,000
103
+ this will not work.
104
+
105
+ 27
106
+ 00:01:09,000 --> 00:01:11,000
107
+ If you try to call mobile.show,
108
+
109
+ 28
110
+ 00:01:11,000 --> 00:01:12,000
111
+ it'll give you an error.
112
+
113
+ 29
114
+ 00:01:12,000 --> 00:01:13,000
115
+ It says,
116
+
117
+ 30
118
+ 00:01:13,000 --> 00:01:14,000
119
+ let's see the error.
120
+
121
+ 31
122
+ 00:01:14,000 --> 00:01:15,000
123
+ It says cannot make a static reference
124
+
125
+ 32
126
+ 00:01:15,000 --> 00:01:17,000
127
+ to a non-static method.
128
+
129
+ 33
130
+ 00:01:17,000 --> 00:01:19,000
131
+ That means you cannot call a non-static method
132
+
133
+ 34
134
+ 00:01:19,000 --> 00:01:20,000
135
+ with the help of a class name.
136
+
137
+ 35
138
+ 00:01:20,000 --> 00:01:23,000
139
+ And that's why you need object here, which you can see.
140
+
141
+ 36
142
+ 00:01:23,000 --> 00:01:24,000
143
+ We are using obj1, obj2 .
144
+
145
+ 37
146
+ 00:01:25,000 --> 00:01:28,000
147
+ But can I call show one from mobile?
148
+
149
+ 38
150
+ 00:01:28,000 --> 00:01:29,000
151
+ Let's try, and we can.
152
+
153
+ 39
154
+ 00:01:29,000 --> 00:01:32,000
155
+ You can see that there's no problem.
156
+
157
+ 40
158
+ 00:01:32,000 --> 00:01:34,000
159
+ So you can call a static method
160
+
161
+ 41
162
+ 00:01:34,000 --> 00:01:36,000
163
+ directly with the help of a class name.
164
+
165
+ 42
166
+ 00:01:36,000 --> 00:01:37,000
167
+ That's what we are doing here.
168
+
169
+ 43
170
+ 00:01:37,000 --> 00:01:39,000
171
+ We're directly calling it with a class name.
172
+
173
+ 44
174
+ 00:01:39,000 --> 00:01:41,000
175
+ Now the question is,
176
+
177
+ 45
178
+ 00:01:41,000 --> 00:01:41,000
179
+ this looks cool, right?
180
+
181
+ 46
182
+ 00:01:41,000 --> 00:01:44,000
183
+ Static method can be used directly with a class name,
184
+
185
+ 47
186
+ 00:01:44,000 --> 00:01:46,000
187
+ but can I use a variables here?
188
+
189
+ 48
190
+ 00:01:46,000 --> 00:01:48,000
191
+ Let's try to do the same thing.
192
+
193
+ 49
194
+ 00:01:48,000 --> 00:01:51,000
195
+ I will just copy this line and paste it here.
196
+
197
+ 50
198
+ 00:01:51,000 --> 00:01:52,000
199
+ Let's see what happens.
200
+
201
+ 51
202
+ 00:01:52,000 --> 00:01:54,000
203
+ The moment you do that,
204
+
205
+ 52
206
+ 00:01:54,000 --> 00:01:55,000
207
+ you can say there's no problem with name.
208
+
209
+ 53
210
+ 00:01:55,000 --> 00:01:58,000
211
+ So that means you can use a static variable
212
+
213
+ 54
214
+ 00:01:58,000 --> 00:02:00,000
215
+ inside a static method,
216
+
217
+ 55
218
+ 00:02:00,000 --> 00:02:03,000
219
+ but you cannot use a non-static variable
220
+
221
+ 56
222
+ 00:02:03,000 --> 00:02:06,000
223
+ inside a static method.
224
+
225
+ 57
226
+ 00:02:06,000 --> 00:02:08,000
227
+ The question is why?
228
+
229
+ 58
230
+ 00:02:08,000 --> 00:02:10,000
231
+ I mean, think about this,
232
+
233
+ 59
234
+ 00:02:10,000 --> 00:02:12,000
235
+ brand and price they instance variable.
236
+
237
+ 60
238
+ 00:02:12,000 --> 00:02:14,000
239
+ That means it'll be different for different objects.
240
+
241
+ 61
242
+ 00:02:14,000 --> 00:02:16,000
243
+ Now, when you call show with obj1,
244
+
245
+ 62
246
+ 00:02:16,000 --> 00:02:17,000
247
+ we know that in this show
248
+
249
+ 63
250
+ 00:02:17,000 --> 00:02:19,000
251
+ when you are printing brand and price,
252
+
253
+ 64
254
+ 00:02:19,000 --> 00:02:21,000
255
+ you're talking about obj1.
256
+
257
+ 65
258
+ 00:02:21,000 --> 00:02:23,000
259
+ When you call show with obj2,
260
+
261
+ 66
262
+ 00:02:23,000 --> 00:02:27,000
263
+ you know that the brand and price will be of obj2.
264
+
265
+ 67
266
+ 00:02:27,000 --> 00:02:29,000
267
+ But then when you call mobile.show1,
268
+
269
+ 68
270
+ 00:02:29,000 --> 00:02:33,000
271
+ how do we know which object you're referring to?
272
+
273
+ 69
274
+ 00:02:33,000 --> 00:02:36,000
275
+ So this brand belongs to obj1 or it belongs to obj2
276
+
277
+ 70
278
+ 00:02:36,000 --> 00:02:37,000
279
+ and that's why it says,
280
+
281
+ 71
282
+ 00:02:37,000 --> 00:02:39,000
283
+ hey, there's a confusion, right?
284
+
285
+ 72
286
+ 00:02:39,000 --> 00:02:40,000
287
+ Let's not do that.
288
+
289
+ 73
290
+ 00:02:40,000 --> 00:02:42,000
291
+ Let's not have a non-static variable
292
+
293
+ 74
294
+ 00:02:42,000 --> 00:02:45,000
295
+ directly getting access in a static method.
296
+
297
+ 75
298
+ 00:02:45,000 --> 00:02:46,000
299
+ It's not possible.
300
+
301
+ 76
302
+ 00:02:46,000 --> 00:02:48,000
303
+ This time I added a directly keyword that
304
+
305
+ 77
306
+ 00:02:48,000 --> 00:02:50,000
307
+ that means indirectly is possible.
308
+
309
+ 78
310
+ 00:02:50,000 --> 00:02:51,000
311
+ Now, how will you do the indirectly?
312
+
313
+ 79
314
+ 00:02:51,000 --> 00:02:52,000
315
+ It's very simple.
316
+
317
+ 80
318
+ 00:02:52,000 --> 00:02:56,000
319
+ What if you can actually pass the object itself?
320
+
321
+ 81
322
+ 00:02:56,000 --> 00:02:57,000
323
+ You can say,
324
+
325
+ 82
326
+ 00:02:57,000 --> 00:03:00,000
327
+ hey, I want to run show 1 for obj1 object.
328
+
329
+ 83
330
+ 00:03:01,000 --> 00:03:02,000
331
+ Now, since you are passing the object,
332
+
333
+ 84
334
+ 00:03:02,000 --> 00:03:04,000
335
+ you have to also accept it here.
336
+
337
+ 85
338
+ 00:03:04,000 --> 00:03:07,000
339
+ So it can say mobile obj.
340
+
341
+ 86
342
+ 00:03:07,000 --> 00:03:10,000
343
+ And now, now since we have the object,
344
+
345
+ 87
346
+ 00:03:10,000 --> 00:03:13,000
347
+ I can refer that with the help of obj1.brand,
348
+
349
+ 88
350
+ 00:03:13,000 --> 00:03:16,000
351
+ I mean, obj.brand on obj.prize.
352
+
353
+ 89
354
+ 00:03:16,000 --> 00:03:19,000
355
+ So basically we cannot directly use a non-static variable
356
+
357
+ 90
358
+ 00:03:19,000 --> 00:03:21,000
359
+ inside a static method.
360
+
361
+ 91
362
+ 00:03:21,000 --> 00:03:23,000
363
+ But if you have object reference, then you can use it.
364
+
365
+ 92
366
+ 00:03:23,000 --> 00:03:25,000
367
+ Because now we can differentiate.
368
+
369
+ 93
370
+ 00:03:25,000 --> 00:03:26,000
371
+ So the brand which I'm talking about
372
+
373
+ 94
374
+ 00:03:26,000 --> 00:03:28,000
375
+ is for obj1, not for obj2.
376
+
377
+ 95
378
+ 00:03:28,000 --> 00:03:29,000
379
+ So that's how we have to do it.
380
+
381
+ 96
382
+ 00:03:29,000 --> 00:03:31,000
383
+ So that's how we work with static method.
384
+
385
+ 97
386
+ 00:03:31,000 --> 00:03:33,000
387
+ Now, if you observe here,
388
+
389
+ 98
390
+ 00:03:33,000 --> 00:03:34,000
391
+ from start we are using this, right?
392
+
393
+ 99
394
+ 00:03:34,000 --> 00:03:37,000
395
+ The main method is static.
396
+
397
+ 100
398
+ 00:03:37,000 --> 00:03:39,000
399
+ Why in this world we have a main static?
400
+
401
+ 101
402
+ 00:03:39,000 --> 00:03:42,000
403
+ Is because if you don't make main static,
404
+
405
+ 102
406
+ 00:03:42,000 --> 00:03:43,000
407
+ if this was a syntax,
408
+
409
+ 103
410
+ 00:03:43,000 --> 00:03:46,000
411
+ the problem is if you don't mention static,
412
+
413
+ 104
414
+ 00:03:46,000 --> 00:03:50,000
415
+ that means main becomes a non-static method,
416
+
417
+ 105
418
+ 00:03:50,000 --> 00:03:53,000
419
+ which means if you want to call main,
420
+
421
+ 106
422
+ 00:03:53,000 --> 00:03:55,000
423
+ we have to first create the object of demo.
424
+
425
+ 107
426
+ 00:03:55,000 --> 00:03:57,000
427
+ Oh, that means you cannot call main
428
+
429
+ 108
430
+ 00:03:57,000 --> 00:03:59,000
431
+ without the object of demo.
432
+
433
+ 109
434
+ 00:03:59,000 --> 00:04:01,000
435
+ But the question is, we all know
436
+
437
+ 110
438
+ 00:04:01,000 --> 00:04:04,000
439
+ that main is a starting point of execution.
440
+
441
+ 111
442
+ 00:04:04,000 --> 00:04:07,000
443
+ If the execution has not started,
444
+
445
+ 112
446
+ 00:04:07,000 --> 00:04:08,000
447
+ how can you create object of demo?
448
+
449
+ 113
450
+ 00:04:08,000 --> 00:04:11,000
451
+ Okay, so if there's a deadlock here, right?
452
+
453
+ 114
454
+ 00:04:11,000 --> 00:04:13,000
455
+ So to solve that problem, what we can do is
456
+
457
+ 115
458
+ 00:04:13,000 --> 00:04:15,000
459
+ we can make this variable as static.
460
+
461
+ 116
462
+ 00:04:15,000 --> 00:04:17,000
463
+ The moment you do that, we are saying,
464
+
465
+ 117
466
+ 00:04:17,000 --> 00:04:18,000
467
+ hey, you know what?
468
+
469
+ 118
470
+ 00:04:18,000 --> 00:04:22,000
471
+ To call main we don't need object of demo.
472
+
473
+ 119
474
+ 00:04:22,000 --> 00:04:24,000
475
+ Problem solved, right?
476
+
477
+ 120
478
+ 00:04:24,000 --> 00:04:26,000
479
+ So yeah, this is how we can solve this problem
480
+
481
+ 121
482
+ 00:04:26,000 --> 00:04:30,000
483
+ and this is what static methods are.
484
+
485
+ 122
486
+ 00:04:30,000 --> 00:04:31,000
487
+ Anything else?
488
+
489
+ 123
490
+ 00:04:31,000 --> 00:04:33,000
491
+ Actually, I think we, it looks good.
492
+
493
+ 124
494
+ 00:04:33,000 --> 00:04:35,000
495
+ In the next video, let's try to see
496
+
497
+ 125
498
+ 00:04:35,000 --> 00:04:37,000
499
+ something more about static.
500
+
501
+ 126
502
+ 00:04:37,000 --> 00:04:39,000
503
+ There's a concept of static block,
504
+
505
+ 127
506
+ 00:04:39,000 --> 00:04:41,000
507
+ which we'll discuss in the next video.
508
+
02 - Core Java/043 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/043 Static block_en.srt ADDED
@@ -0,0 +1,800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: Now we know what is static variables,
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:06,000
11
+ static methods, right?
12
+
13
+ 4
14
+ 00:00:06,000 --> 00:00:08,000
15
+ Now let's try to expand this more.
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:09,000
19
+ To simplify this,
20
+
21
+ 6
22
+ 00:00:09,000 --> 00:00:10,000
23
+ what I will do is I will remove the static method
24
+
25
+ 7
26
+ 00:00:10,000 --> 00:00:11,000
27
+ for some time
28
+
29
+ 8
30
+ 00:00:11,000 --> 00:00:14,000
31
+ and I will also decrease this code.
32
+
33
+ 9
34
+ 00:00:14,000 --> 00:00:16,000
35
+ Let's only work with one object now.
36
+
37
+ 10
38
+ 00:00:16,000 --> 00:00:20,000
39
+ And here, see, normally when you work with variables,
40
+
41
+ 11
42
+ 00:00:20,000 --> 00:00:23,000
43
+ so we know that this is an instance variable,
44
+
45
+ 12
46
+ 00:00:23,000 --> 00:00:26,000
47
+ and this is a static variable, right, the name.
48
+
49
+ 13
50
+ 00:00:26,000 --> 00:00:29,000
51
+ Now to instantiate the instance variable,
52
+
53
+ 14
54
+ 00:00:29,000 --> 00:00:29,000
55
+ what do we do?
56
+
57
+ 15
58
+ 00:00:29,000 --> 00:00:33,000
59
+ Of course we can instantiate the variables from here,
60
+
61
+ 16
62
+ 00:00:33,000 --> 00:00:34,000
63
+ but then what if you want
64
+
65
+ 17
66
+ 00:00:34,000 --> 00:00:36,000
67
+ to instantiate the variable on this line,
68
+
69
+ 18
70
+ 00:00:36,000 --> 00:00:37,000
71
+ if you want to give some value?
72
+
73
+ 19
74
+ 00:00:37,000 --> 00:00:39,000
75
+ Not instantiate, if you want to initialize the variable,
76
+
77
+ 20
78
+ 00:00:39,000 --> 00:00:40,000
79
+ what you will do?
80
+
81
+ 21
82
+ 00:00:40,000 --> 00:00:42,000
83
+ So basically we have seen one concept,
84
+
85
+ 22
86
+ 00:00:42,000 --> 00:00:43,000
87
+ right, which is constructor.
88
+
89
+ 23
90
+ 00:00:43,000 --> 00:00:48,000
91
+ So using constructor, we can say, okay, public Mobile,
92
+
93
+ 24
94
+ 00:00:49,000 --> 00:00:51,000
95
+ and we can give some default values to it, right?
96
+
97
+ 25
98
+ 00:00:51,000 --> 00:00:53,000
99
+ So by default, the brand will be empty string,
100
+
101
+ 26
102
+ 00:00:53,000 --> 00:00:55,000
103
+ and by default the price will be,
104
+
105
+ 27
106
+ 00:00:55,000 --> 00:00:57,000
107
+ let's say $200, right?
108
+
109
+ 28
110
+ 00:00:57,000 --> 00:01:01,000
111
+ So this is the default brand, default text,
112
+
113
+ 29
114
+ 00:01:01,000 --> 00:01:02,000
115
+ and default number, right?
116
+
117
+ 30
118
+ 00:01:02,000 --> 00:01:03,000
119
+ Which we want to give.
120
+
121
+ 31
122
+ 00:01:03,000 --> 00:01:04,000
123
+ What about name?
124
+
125
+ 32
126
+ 00:01:04,000 --> 00:01:06,000
127
+ I can also give a default name to a name,
128
+
129
+ 33
130
+ 00:01:06,000 --> 00:01:09,000
131
+ which is phone in this case, let's say.
132
+
133
+ 34
134
+ 00:01:09,000 --> 00:01:10,000
135
+ And we can do that.
136
+
137
+ 35
138
+ 00:01:10,000 --> 00:01:12,000
139
+ We can initialize the static variable
140
+
141
+ 36
142
+ 00:01:12,000 --> 00:01:13,000
143
+ inside a constructor,
144
+
145
+ 37
146
+ 00:01:13,000 --> 00:01:14,000
147
+ and there's no harm in that.
148
+
149
+ 38
150
+ 00:01:14,000 --> 00:01:19,000
151
+ Now the problem is every time you create an object,
152
+
153
+ 39
154
+ 00:01:19,000 --> 00:01:20,000
155
+ every time you create one more object,
156
+
157
+ 40
158
+ 00:01:20,000 --> 00:01:22,000
159
+ it'll call the construct, right?
160
+
161
+ 41
162
+ 00:01:22,000 --> 00:01:24,000
163
+ And don't you think it makes sense for this tool
164
+
165
+ 42
166
+ 00:01:24,000 --> 00:01:26,000
167
+ to initialize every time,
168
+
169
+ 43
170
+ 00:01:26,000 --> 00:01:29,000
171
+ but why name has to initialize every time?
172
+
173
+ 44
174
+ 00:01:29,000 --> 00:01:32,000
175
+ I feel that the name variable, which is static,
176
+
177
+ 45
178
+ 00:01:32,000 --> 00:01:34,000
179
+ should be initialized only once.
180
+
181
+ 46
182
+ 00:01:34,000 --> 00:01:34,000
183
+ What do you feel?
184
+
185
+ 47
186
+ 00:01:34,000 --> 00:01:36,000
187
+ Of course the same thing, right?
188
+
189
+ 48
190
+ 00:01:36,000 --> 00:01:37,000
191
+ How will you do that?
192
+
193
+ 49
194
+ 00:01:37,000 --> 00:01:38,000
195
+ So if you mention that here,
196
+
197
+ 50
198
+ 00:01:38,000 --> 00:01:40,000
199
+ of course every time you call the constructor,
200
+
201
+ 51
202
+ 00:01:40,000 --> 00:01:41,000
203
+ it will initialize.
204
+
205
+ 52
206
+ 00:01:41,000 --> 00:01:42,000
207
+ We don't wanna do that.
208
+
209
+ 53
210
+ 00:01:42,000 --> 00:01:43,000
211
+ Now to achieve that,
212
+
213
+ 54
214
+ 00:01:43,000 --> 00:01:47,000
215
+ we have a special block called a static block.
216
+
217
+ 55
218
+ 00:01:47,000 --> 00:01:48,000
219
+ Now, in the static block,
220
+
221
+ 56
222
+ 00:01:48,000 --> 00:01:52,000
223
+ we can basically initialize the variable,
224
+
225
+ 57
226
+ 00:01:52,000 --> 00:01:53,000
227
+ the static variable.
228
+
229
+ 58
230
+ 00:01:53,000 --> 00:01:54,000
231
+ Now the good thing
232
+
233
+ 59
234
+ 00:01:54,000 --> 00:01:57,000
235
+ about this is the static block will be called only once.
236
+
237
+ 60
238
+ 00:01:57,000 --> 00:02:00,000
239
+ Irrespective how many objects you create,
240
+
241
+ 61
242
+ 00:02:00,000 --> 00:02:02,000
243
+ it'll call the static block only once.
244
+
245
+ 62
246
+ 00:02:02,000 --> 00:02:04,000
247
+ So what I will do is just to demonstrate
248
+
249
+ 63
250
+ 00:02:04,000 --> 00:02:08,000
251
+ that I will create one more object here, let's say.
252
+
253
+ 64
254
+ 00:02:08,000 --> 00:02:09,000
255
+ And I will not assign any value to it,
256
+
257
+ 65
258
+ 00:02:09,000 --> 00:02:14,000
259
+ just to default values obj2, second object.
260
+
261
+ 66
262
+ 00:02:14,000 --> 00:02:16,000
263
+ So it'll call the constructor two times.
264
+
265
+ 67
266
+ 00:02:16,000 --> 00:02:19,000
267
+ It'll call the static block only once.
268
+
269
+ 68
270
+ 00:02:19,000 --> 00:02:19,000
271
+ To prove that,
272
+
273
+ 69
274
+ 00:02:19,000 --> 00:02:21,000
275
+ what I will do is I will just print something.
276
+
277
+ 70
278
+ 00:02:21,000 --> 00:02:24,000
279
+ I will say in static block.
280
+
281
+ 71
282
+ 00:02:24,000 --> 00:02:25,000
283
+ Now the syntax for static block is very simple.
284
+
285
+ 72
286
+ 00:02:25,000 --> 00:02:27,000
287
+ It's static keyword,
288
+
289
+ 73
290
+ 00:02:27,000 --> 00:02:29,000
291
+ and then you just open and close.
292
+
293
+ 74
294
+ 00:02:29,000 --> 00:02:30,000
295
+ There's no bracket or something.
296
+
297
+ 75
298
+ 00:02:30,000 --> 00:02:33,000
299
+ It's just a simple block, okay?
300
+
301
+ 76
302
+ 00:02:33,000 --> 00:02:33,000
303
+ And in the constructor as well,
304
+
305
+ 77
306
+ 00:02:33,000 --> 00:02:38,000
307
+ I will say in constructor, okay?
308
+
309
+ 78
310
+ 00:02:38,000 --> 00:02:42,000
311
+ And now with this, let me just compile this code, okay?
312
+
313
+ 79
314
+ 00:02:42,000 --> 00:02:43,000
315
+ There is an issue.
316
+
317
+ 80
318
+ 00:02:43,000 --> 00:02:45,000
319
+ I have returned one extra, okay.
320
+
321
+ 81
322
+ 00:02:45,000 --> 00:02:49,000
323
+ I have removed the curly brackets from here.
324
+
325
+ 82
326
+ 00:02:49,000 --> 00:02:52,000
327
+ So compile and run.
328
+
329
+ 83
330
+ 00:02:52,000 --> 00:02:54,000
331
+ So you can see it is calling the static block only once,
332
+
333
+ 84
334
+ 00:02:54,000 --> 00:02:57,000
335
+ and it's calling constructor two times.
336
+
337
+ 85
338
+ 00:02:57,000 --> 00:02:58,000
339
+ There's one more issue,
340
+
341
+ 86
342
+ 00:02:58,000 --> 00:03:01,000
343
+ why static block is called first
344
+
345
+ 87
346
+ 00:03:01,000 --> 00:03:03,000
347
+ even before the constructor is calling static block.
348
+
349
+ 88
350
+ 00:03:03,000 --> 00:03:04,000
351
+ And that's weird.
352
+
353
+ 89
354
+ 00:03:04,000 --> 00:03:05,000
355
+ Is it the sequence?
356
+
357
+ 90
358
+ 00:03:05,000 --> 00:03:07,000
359
+ Let's try, let me just put this
360
+
361
+ 91
362
+ 00:03:07,000 --> 00:03:09,000
363
+ after the constructor.
364
+
365
+ 92
366
+ 00:03:09,000 --> 00:03:11,000
367
+ Let's see if it doesn't make any sense.
368
+
369
+ 93
370
+ 00:03:11,000 --> 00:03:13,000
371
+ Anyway, Java does not follow the sequence.
372
+
373
+ 94
374
+ 00:03:13,000 --> 00:03:16,000
375
+ But just to confirm,
376
+
377
+ 95
378
+ 00:03:16,000 --> 00:03:20,000
379
+ you can see the static block is still getting called first.
380
+
381
+ 96
382
+ 00:03:20,000 --> 00:03:23,000
383
+ Now to understand that, let's go to the diagram here.
384
+
385
+ 97
386
+ 00:03:23,000 --> 00:03:24,000
387
+ See what happens.
388
+
389
+ 98
390
+ 00:03:24,000 --> 00:03:26,000
391
+ There are two words,
392
+
393
+ 99
394
+ 00:03:26,000 --> 00:03:27,000
395
+ and we only focus on one word.
396
+
397
+ 100
398
+ 00:03:27,000 --> 00:03:30,000
399
+ Every time you get the object, that two steps,
400
+
401
+ 101
402
+ 00:03:30,000 --> 00:03:34,000
403
+ one, your class loads,
404
+
405
+ 102
406
+ 00:03:35,000 --> 00:03:39,000
407
+ and then your objects are, okay,
408
+
409
+ 103
410
+ 00:03:39,000 --> 00:03:40,000
411
+ so first your class loads
412
+
413
+ 104
414
+ 00:03:40,000 --> 00:03:42,000
415
+ and then your object gets instantiated.
416
+
417
+ 105
418
+ 00:03:42,000 --> 00:03:44,000
419
+ So there are two steps.
420
+
421
+ 106
422
+ 00:03:44,000 --> 00:03:46,000
423
+ Every time you create the object,
424
+
425
+ 107
426
+ 00:03:46,000 --> 00:03:48,000
427
+ there are two steps, class loads
428
+
429
+ 108
430
+ 00:03:48,000 --> 00:03:50,000
431
+ and object will then will get initialized.
432
+
433
+ 109
434
+ 00:03:50,000 --> 00:03:53,000
435
+ The thing is, the class will load only once.
436
+
437
+ 110
438
+ 00:03:53,000 --> 00:03:57,000
439
+ So basically in your JVM, you have a special area here,
440
+
441
+ 111
442
+ 00:03:57,000 --> 00:04:00,000
443
+ which is called a class loader, okay?
444
+
445
+ 112
446
+ 00:04:00,000 --> 00:04:03,000
447
+ And this will have all the class which are loaded.
448
+
449
+ 113
450
+ 00:04:03,000 --> 00:04:04,000
451
+ And by default, of course you don't have
452
+
453
+ 114
454
+ 00:04:04,000 --> 00:04:05,000
455
+ any class loaded, right?
456
+
457
+ 115
458
+ 00:04:05,000 --> 00:04:09,000
459
+ So the class will get loaded from your library
460
+
461
+ 116
462
+ 00:04:09,000 --> 00:04:11,000
463
+ to the class loader.
464
+
465
+ 117
466
+ 00:04:11,000 --> 00:04:13,000
467
+ And it'll happen only once.
468
+
469
+ 118
470
+ 00:04:13,000 --> 00:04:15,000
471
+ So for the first object, when it sees, "Hey,
472
+
473
+ 119
474
+ 00:04:15,000 --> 00:04:18,000
475
+ this object creation, it'll load the class first,"
476
+
477
+ 120
478
+ 00:04:18,000 --> 00:04:20,000
479
+ and then it'll create the object.
480
+
481
+ 121
482
+ 00:04:20,000 --> 00:04:22,000
483
+ Now, every time you load a class,
484
+
485
+ 122
486
+ 00:04:22,000 --> 00:04:25,000
487
+ it'll call the static block.
488
+
489
+ 123
490
+ 00:04:25,000 --> 00:04:27,000
491
+ Now, since class loading happens first,
492
+
493
+ 124
494
+ 00:04:27,000 --> 00:04:29,000
495
+ and that's why it'll call the static block first,
496
+
497
+ 125
498
+ 00:04:29,000 --> 00:04:31,000
499
+ and then it'll create the object.
500
+
501
+ 126
502
+ 00:04:31,000 --> 00:04:34,000
503
+ And that's why it'll call the constructor
504
+
505
+ 127
506
+ 00:04:34,000 --> 00:04:36,000
507
+ after static block.
508
+
509
+ 128
510
+ 00:04:36,000 --> 00:04:38,000
511
+ Now, irrespective of how many objects you create,
512
+
513
+ 129
514
+ 00:04:38,000 --> 00:04:40,000
515
+ the class is already loaded, right?
516
+
517
+ 130
518
+ 00:04:40,000 --> 00:04:42,000
519
+ So you can simply create the next object
520
+
521
+ 131
522
+ 00:04:42,000 --> 00:04:43,000
523
+ without loading because it's already loaded.
524
+
525
+ 132
526
+ 00:04:43,000 --> 00:04:46,000
527
+ Now my question is, if that is how it is working,
528
+
529
+ 133
530
+ 00:04:46,000 --> 00:04:48,000
531
+ what if I don't create any object?
532
+
533
+ 134
534
+ 00:04:48,000 --> 00:04:50,000
535
+ I'm not getting any object now.
536
+
537
+ 135
538
+ 00:04:50,000 --> 00:04:52,000
539
+ So if you don't create the object,
540
+
541
+ 136
542
+ 00:04:52,000 --> 00:04:54,000
543
+ of course it'll not call the constructor.
544
+
545
+ 137
546
+ 00:04:54,000 --> 00:04:55,000
547
+ But what about static block?
548
+
549
+ 138
550
+ 00:04:55,000 --> 00:04:57,000
551
+ It'll not even call the static block.
552
+
553
+ 139
554
+ 00:04:57,000 --> 00:05:00,000
555
+ If you can see, we don't have any output, oh, okay.
556
+
557
+ 140
558
+ 00:05:00,000 --> 00:05:02,000
559
+ So that means if you don't create the object,
560
+
561
+ 141
562
+ 00:05:02,000 --> 00:05:05,000
563
+ it'll not load the class as well.
564
+
565
+ 142
566
+ 00:05:05,000 --> 00:05:06,000
567
+ But what if you wanna do that?
568
+
569
+ 143
570
+ 00:05:06,000 --> 00:05:10,000
571
+ What if you want to load the class?
572
+
573
+ 144
574
+ 00:05:10,000 --> 00:05:11,000
575
+ How would you do that?
576
+
577
+ 145
578
+ 00:05:11,000 --> 00:05:14,000
579
+ Now for that, we have a special class inside Java,
580
+
581
+ 146
582
+ 00:05:14,000 --> 00:05:16,000
583
+ which is called a Class class.
584
+
585
+ 147
586
+ 00:05:16,000 --> 00:05:17,000
587
+ Yeah, that's a class.
588
+
589
+ 148
590
+ 00:05:17,000 --> 00:05:20,000
591
+ Okay, I know Java has been weird.
592
+
593
+ 149
594
+ 00:05:20,000 --> 00:05:22,000
595
+ We have Object class, we have Class class,
596
+
597
+ 150
598
+ 00:05:22,000 --> 00:05:23,000
599
+ but that's how it is designed.
600
+
601
+ 151
602
+ 00:05:23,000 --> 00:05:26,000
603
+ So Java Class, if you go there,
604
+
605
+ 152
606
+ 00:05:26,000 --> 00:05:29,000
607
+ you can see it's a class and it has a lot of methods to it.
608
+
609
+ 153
610
+ 00:05:29,000 --> 00:05:32,000
611
+ One of the methods which we want to use here is forName.
612
+
613
+ 154
614
+ 00:05:32,000 --> 00:05:36,000
615
+ Now forName is a method which does one thing
616
+
617
+ 155
618
+ 00:05:36,000 --> 00:05:38,000
619
+ which loads your class.
620
+
621
+ 156
622
+ 00:05:38,000 --> 00:05:40,000
623
+ And you just have to mention your class name.
624
+
625
+ 157
626
+ 00:05:40,000 --> 00:05:41,000
627
+ What's the class name?
628
+
629
+ 158
630
+ 00:05:41,000 --> 00:05:43,000
631
+ Well, the class name is Mobile.
632
+
633
+ 159
634
+ 00:05:43,000 --> 00:05:44,000
635
+ So in this you can mention the class name.
636
+
637
+ 160
638
+ 00:05:44,000 --> 00:05:46,000
639
+ That's it, okay?
640
+
641
+ 161
642
+ 00:05:46,000 --> 00:05:48,000
643
+ The only problem is it throws an exception, okay?
644
+
645
+ 162
646
+ 00:05:48,000 --> 00:05:50,000
647
+ At this point we have not talked about exception,
648
+
649
+ 163
650
+ 00:05:50,000 --> 00:05:52,000
651
+ but just ignore this line.
652
+
653
+ 164
654
+ 00:05:52,000 --> 00:05:55,000
655
+ We'll talk about this in detail later once we start
656
+
657
+ 165
658
+ 00:05:55,000 --> 00:05:56,000
659
+ with the exception concept.
660
+
661
+ 166
662
+ 00:05:56,000 --> 00:05:58,000
663
+ But as of now, just to make it work,
664
+
665
+ 167
666
+ 00:05:58,000 --> 00:06:00,000
667
+ I'm just writing this line, ignore it.
668
+
669
+ 168
670
+ 00:06:00,000 --> 00:06:04,000
671
+ What's important is the class.forName will load your class.
672
+
673
+ 169
674
+ 00:06:04,000 --> 00:06:07,000
675
+ If I go to forName, you can see forName is a method,
676
+
677
+ 170
678
+ 00:06:07,000 --> 00:06:08,000
679
+ and it's a static method.
680
+
681
+ 171
682
+ 00:06:08,000 --> 00:06:11,000
683
+ So you can call this with a class name.
684
+
685
+ 172
686
+ 00:06:12,000 --> 00:06:14,000
687
+ And this particular method,
688
+
689
+ 173
690
+ 00:06:15,000 --> 00:06:18,000
691
+ do they have any definition mentioned?
692
+
693
+ 174
694
+ 00:06:18,000 --> 00:06:20,000
695
+ Okay, so it says the system class loader is used.
696
+
697
+ 175
698
+ 00:06:20,000 --> 00:06:23,000
699
+ So basically it'll load the system class loader
700
+
701
+ 176
702
+ 00:06:23,000 --> 00:06:26,000
703
+ to load this class.
704
+
705
+ 177
706
+ 00:06:26,000 --> 00:06:28,000
707
+ Okay, so which class, Mobile class.
708
+
709
+ 178
710
+ 00:06:28,000 --> 00:06:31,000
711
+ Okay, so now if I just write this line,
712
+
713
+ 179
714
+ 00:06:31,000 --> 00:06:32,000
715
+ it'll not create the object,
716
+
717
+ 180
718
+ 00:06:32,000 --> 00:06:36,000
719
+ it'll just instantiate it, compile, run.
720
+
721
+ 181
722
+ 00:06:36,000 --> 00:06:40,000
723
+ You can see it says a new static block.
724
+
725
+ 182
726
+ 00:06:40,000 --> 00:06:42,000
727
+ Okay, that means you're just loading the class.
728
+
729
+ 183
730
+ 00:06:42,000 --> 00:06:44,000
731
+ So basically that's how you load your class.
732
+
733
+ 184
734
+ 00:06:44,000 --> 00:06:49,000
735
+ You can simply use this line to load your class.
736
+
737
+ 185
738
+ 00:06:49,000 --> 00:06:50,000
739
+ Normally when you build a project,
740
+
741
+ 186
742
+ 00:06:50,000 --> 00:06:51,000
743
+ you don't actually use this feature.
744
+
745
+ 187
746
+ 00:06:51,000 --> 00:06:53,000
747
+ Yes, there are some situation where you use it.
748
+
749
+ 188
750
+ 00:06:53,000 --> 00:06:57,000
751
+ Example, when we start with JDBC, we'll talk about this one,
752
+
753
+ 189
754
+ 00:06:57,000 --> 00:06:59,000
755
+ but we normally don't use it.
756
+
757
+ 190
758
+ 00:06:59,000 --> 00:07:00,000
759
+ I'm just using this just to show you how
760
+
761
+ 191
762
+ 00:07:00,000 --> 00:07:02,000
763
+ to call a static block,
764
+
765
+ 192
766
+ 00:07:02,000 --> 00:07:03,000
767
+ how to load a class.
768
+
769
+ 193
770
+ 00:07:03,000 --> 00:07:05,000
771
+ Okay, I hope this video makes sense
772
+
773
+ 194
774
+ 00:07:05,000 --> 00:07:07,000
775
+ where we talked about static block.
776
+
777
+ 195
778
+ 00:07:07,000 --> 00:07:11,000
779
+ So static block is used to initialize the static variables.
780
+
781
+ 196
782
+ 00:07:11,000 --> 00:07:12,000
783
+ So that's it from this video in which we talked
784
+
785
+ 197
786
+ 00:07:12,000 --> 00:07:14,000
787
+ about static block.
788
+
789
+ 198
790
+ 00:07:14,000 --> 00:07:16,000
791
+ In the other videos we have talked about static keyword,
792
+
793
+ 199
794
+ 00:07:16,000 --> 00:07:18,000
795
+ static variables, static methods,
796
+
797
+ 200
798
+ 00:07:18,000 --> 00:07:19,000
799
+ and yeah, that's about static.
800
+
02 - Core Java/044 Encapsulation_en.srt ADDED
@@ -0,0 +1,1144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (soft music plays)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: In this video, let's talk about Encapsulation.
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:07,000
11
+ Now I know that's a new term,
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:09,000
15
+ but when we started with OOPs concept,
16
+
17
+ 5
18
+ 00:00:09,000 --> 00:00:12,000
19
+ now Encapsulation is a part of OOPs.
20
+
21
+ 6
22
+ 00:00:12,000 --> 00:00:16,000
23
+ So when I say let's implement Object Oriented Programming,
24
+
25
+ 7
26
+ 00:00:16,000 --> 00:00:18,000
27
+ so yeah, we have talked about class,
28
+
29
+ 8
30
+ 00:00:18,000 --> 00:00:19,000
31
+ we have talked about objects,
32
+
33
+ 9
34
+ 00:00:19,000 --> 00:00:21,000
35
+ and the next step is Encapsulation here.
36
+
37
+ 10
38
+ 00:00:21,000 --> 00:00:24,000
39
+ Now by word, what Encapsulation means?
40
+
41
+ 11
42
+ 00:00:24,000 --> 00:00:25,000
43
+ We have the concept of capsules
44
+
45
+ 12
46
+ 00:00:25,000 --> 00:00:28,000
47
+ where we have medicine powder there?
48
+
49
+ 13
50
+ 00:00:28,000 --> 00:00:30,000
51
+ So basically we can imagine capsule
52
+
53
+ 14
54
+ 00:00:30,000 --> 00:00:34,000
55
+ as something which is keeping it closed, keeping it tight,
56
+
57
+ 15
58
+ 00:00:34,000 --> 00:00:37,000
59
+ and no one from the outside world can use it.
60
+
61
+ 16
62
+ 00:00:37,000 --> 00:00:39,000
63
+ That makes sense, right?
64
+
65
+ 17
66
+ 00:00:39,000 --> 00:00:41,000
67
+ So what we can do here is let's say,
68
+
69
+ 18
70
+ 00:00:41,000 --> 00:00:42,000
71
+ let's design a class, okay?
72
+
73
+ 19
74
+ 00:00:42,000 --> 00:00:44,000
75
+ And let's name this class as Human.
76
+
77
+ 20
78
+ 00:00:44,000 --> 00:00:46,000
79
+ I know we can use different names,
80
+
81
+ 21
82
+ 00:00:46,000 --> 00:00:47,000
83
+ but let's go with Human here.
84
+
85
+ 22
86
+ 00:00:47,000 --> 00:00:51,000
87
+ And I know we are aliens, but let's say this is Human.
88
+
89
+ 23
90
+ 00:00:51,000 --> 00:00:54,000
91
+ Now here, when you have this Human class,
92
+
93
+ 24
94
+ 00:00:54,000 --> 00:00:56,000
95
+ a Human will have some parameters, right?
96
+
97
+ 25
98
+ 00:00:56,000 --> 00:00:59,000
99
+ Example, if you remember, we have talked about this
100
+
101
+ 26
102
+ 00:00:59,000 --> 00:01:01,000
103
+ before, as a Human or as a person,
104
+
105
+ 27
106
+ 00:01:01,000 --> 00:01:03,000
107
+ we know a lot of different stuff.
108
+
109
+ 28
110
+ 00:01:03,000 --> 00:01:05,000
111
+ So in your mind you have a lot of different concepts
112
+
113
+ 29
114
+ 00:01:05,000 --> 00:01:07,000
115
+ or you know a lot of things.
116
+
117
+ 30
118
+ 00:01:07,000 --> 00:01:11,000
119
+ Example, you know your name, you know where you stay,
120
+
121
+ 31
122
+ 00:01:11,000 --> 00:01:12,000
123
+ you know your favorite actor,
124
+
125
+ 32
126
+ 00:01:12,000 --> 00:01:14,000
127
+ you know your favorite trainer.
128
+
129
+ 33
130
+ 00:01:14,000 --> 00:01:16,000
131
+ Of course you can name, you can use my name there,
132
+
133
+ 34
134
+ 00:01:16,000 --> 00:01:18,000
135
+ but just kidding.
136
+
137
+ 35
138
+ 00:01:18,000 --> 00:01:20,000
139
+ So we have different information, right?
140
+
141
+ 36
142
+ 00:01:20,000 --> 00:01:21,000
143
+ Now, can you imagine this,
144
+
145
+ 37
146
+ 00:01:21,000 --> 00:01:25,000
147
+ that all the information are actually stored in your brain
148
+
149
+ 38
150
+ 00:01:25,000 --> 00:01:27,000
151
+ as a variable box?
152
+
153
+ 39
154
+ 00:01:27,000 --> 00:01:30,000
155
+ I'm a big fan of Pixel movie, which is,
156
+
157
+ 40
158
+ 00:01:30,000 --> 00:01:32,000
159
+ I don't know the exact movie name,
160
+
161
+ 41
162
+ 00:01:32,000 --> 00:01:34,000
163
+ but you know, Pac-Man basically eats people
164
+
165
+ 42
166
+ 00:01:34,000 --> 00:01:36,000
167
+ and then they become pixels.
168
+
169
+ 43
170
+ 00:01:36,000 --> 00:01:40,000
171
+ So you can imagine the data in your mind is cube, okay?
172
+
173
+ 44
174
+ 00:01:40,000 --> 00:01:42,000
175
+ And in that box, you have the data.
176
+
177
+ 45
178
+ 00:01:42,000 --> 00:01:46,000
179
+ Example, your name is stored in a box, which name Navin,
180
+
181
+ 46
182
+ 00:01:46,000 --> 00:01:48,000
183
+ or which name is equal to
184
+
185
+ 47
186
+ 00:01:48,000 --> 00:01:50,000
187
+ and in the box will be having a value.
188
+
189
+ 48
190
+ 00:01:50,000 --> 00:01:51,000
191
+ For me it's Navin.
192
+
193
+ 49
194
+ 00:01:51,000 --> 00:01:53,000
195
+ Let's say, your favorite actor,
196
+
197
+ 50
198
+ 00:01:53,000 --> 00:01:56,000
199
+ so you'll be having my favorite actor,
200
+
201
+ 51
202
+ 00:01:56,000 --> 00:01:58,000
203
+ and inside the box will be having a value.
204
+
205
+ 52
206
+ 00:01:58,000 --> 00:02:02,000
207
+ So what I'm saying is, all the data is stored in your brain
208
+
209
+ 53
210
+ 00:02:02,000 --> 00:02:04,000
211
+ in the format of boxes, variables.
212
+
213
+ 54
214
+ 00:02:04,000 --> 00:02:07,000
215
+ Now of course you can use these variables, right?
216
+
217
+ 55
218
+ 00:02:07,000 --> 00:02:08,000
219
+ So let's say my name is Navin,
220
+
221
+ 56
222
+ 00:02:08,000 --> 00:02:10,000
223
+ and let's say if I'm walking on a street
224
+
225
+ 57
226
+ 00:02:10,000 --> 00:02:14,000
227
+ and if somebody is asking my name, I might provide my name.
228
+
229
+ 58
230
+ 00:02:14,000 --> 00:02:17,000
231
+ What if somebody is asking my email address?
232
+
233
+ 59
234
+ 00:02:17,000 --> 00:02:19,000
235
+ I might provide them my email address depending
236
+
237
+ 60
238
+ 00:02:19,000 --> 00:02:20,000
239
+ upon who that person is.
240
+
241
+ 61
242
+ 00:02:20,000 --> 00:02:25,000
243
+ What if somebody is asking for my children's name,
244
+
245
+ 62
246
+ 00:02:25,000 --> 00:02:27,000
247
+ my wife name, my family name, my Facebook password?
248
+
249
+ 63
250
+ 00:02:27,000 --> 00:02:30,000
251
+ No, I'm not going to share those things,
252
+
253
+ 64
254
+ 00:02:30,000 --> 00:02:32,000
255
+ it's because there's something called privacy, right?
256
+
257
+ 65
258
+ 00:02:32,000 --> 00:02:34,000
259
+ And yeah, I know a lot of people don't believe in privacy,
260
+
261
+ 66
262
+ 00:02:34,000 --> 00:02:36,000
263
+ but of course no one should be able
264
+
265
+ 67
266
+ 00:02:36,000 --> 00:02:38,000
267
+ to get your data directly, right?
268
+
269
+ 68
270
+ 00:02:38,000 --> 00:02:40,000
271
+ It's not like your data is available
272
+
273
+ 69
274
+ 00:02:40,000 --> 00:02:41,000
275
+ for the entire world to see.
276
+
277
+ 70
278
+ 00:02:41,000 --> 00:02:43,000
279
+ It's there, it's closed.
280
+
281
+ 71
282
+ 00:02:43,000 --> 00:02:44,000
283
+ No one can see the data.
284
+
285
+ 72
286
+ 00:02:44,000 --> 00:02:45,000
287
+ Of course they can see my Facebook profile,
288
+
289
+ 73
290
+ 00:02:45,000 --> 00:02:48,000
291
+ but no one can see the data inside your brain.
292
+
293
+ 74
294
+ 00:02:48,000 --> 00:02:50,000
295
+ That's important.
296
+
297
+ 75
298
+ 00:02:50,000 --> 00:02:52,000
299
+ If they want to know your data, they have to ask
300
+
301
+ 76
302
+ 00:02:52,000 --> 00:02:56,000
303
+ and you can decide do you want to share or not?
304
+
305
+ 77
306
+ 00:02:56,000 --> 00:02:59,000
307
+ In the same way, let's say we have this Human class
308
+
309
+ 78
310
+ 00:02:59,000 --> 00:03:01,000
311
+ and in this Human class we have a variable called "age"
312
+
313
+ 79
314
+ 00:03:01,000 --> 00:03:03,000
315
+ and we have a string which is "name",
316
+
317
+ 80
318
+ 00:03:03,000 --> 00:03:04,000
319
+ that's it, just two variables.
320
+
321
+ 81
322
+ 00:03:04,000 --> 00:03:08,000
323
+ And now if I want to access those data, of course I have
324
+
325
+ 82
326
+ 00:03:08,000 --> 00:03:10,000
327
+ to create object of Human here.
328
+
329
+ 83
330
+ 00:03:10,000 --> 00:03:13,000
331
+ And let's say this is the Human object, new Human.
332
+
333
+ 84
334
+ 00:03:13,000 --> 00:03:16,000
335
+ And once you got this object, with this object,
336
+
337
+ 85
338
+ 00:03:16,000 --> 00:03:17,000
339
+ you can fetch data, right?
340
+
341
+ 86
342
+ 00:03:17,000 --> 00:03:19,000
343
+ Of course you can set the date values as well.
344
+
345
+ 87
346
+ 00:03:19,000 --> 00:03:21,000
347
+ And for this particular object,
348
+
349
+ 88
350
+ 00:03:21,000 --> 00:03:24,000
351
+ I can say obj.age is, let's say 11.
352
+
353
+ 89
354
+ 00:03:24,000 --> 00:03:29,000
355
+ And obj.name is, let's say Navin.
356
+
357
+ 90
358
+ 00:03:29,000 --> 00:03:30,000
359
+ I know that's not my age,
360
+
361
+ 91
362
+ 00:03:30,000 --> 00:03:33,000
363
+ but at this point it's okay, so we got these values
364
+
365
+ 92
366
+ 00:03:33,000 --> 00:03:35,000
367
+ and we got this object created here.
368
+
369
+ 93
370
+ 00:03:35,000 --> 00:03:40,000
371
+ Now what I wanna do is, what if someone ask me, "Hey Human,"
372
+
373
+ 94
374
+ 00:03:40,000 --> 00:03:42,000
375
+ or maybe someone is trying to directly trying
376
+
377
+ 95
378
+ 00:03:42,000 --> 00:03:43,000
379
+ to fetch the data.
380
+
381
+ 96
382
+ 00:03:43,000 --> 00:03:47,000
383
+ Example, if I say S out and if I try to say obj name.
384
+
385
+ 97
386
+ 00:03:47,000 --> 00:03:51,000
387
+ Now what we are doing is just by using the object,
388
+
389
+ 98
390
+ 00:03:51,000 --> 00:03:53,000
391
+ anyone can fetch data, okay?
392
+
393
+ 99
394
+ 00:03:53,000 --> 00:03:57,000
395
+ And this will work, okay? It'll not give any issue.
396
+
397
+ 100
398
+ 00:03:57,000 --> 00:03:59,000
399
+ So I will say compile and run.
400
+
401
+ 101
402
+ 00:03:59,000 --> 00:04:01,000
403
+ You can see we are able to fetch data
404
+
405
+ 102
406
+ 00:04:01,000 --> 00:04:04,000
407
+ and syntactically there's no issue.
408
+
409
+ 103
410
+ 00:04:04,000 --> 00:04:06,000
411
+ But then if you really think that we have
412
+
413
+ 104
414
+ 00:04:06,000 --> 00:04:08,000
415
+ to implement software for the physical world
416
+
417
+ 105
418
+ 00:04:08,000 --> 00:04:11,000
419
+ or the real world, it should match with the real world.
420
+
421
+ 106
422
+ 00:04:11,000 --> 00:04:13,000
423
+ Not all data are directly accessible
424
+
425
+ 107
426
+ 00:04:13,000 --> 00:04:15,000
427
+ and we want to control it.
428
+
429
+ 108
430
+ 00:04:15,000 --> 00:04:16,000
431
+ So one way to do that is
432
+
433
+ 109
434
+ 00:04:16,000 --> 00:04:19,000
435
+ what you can do is you can make your variables private.
436
+
437
+ 110
438
+ 00:04:19,000 --> 00:04:21,000
439
+ Now what do you mean by this private keyword?
440
+
441
+ 111
442
+ 00:04:21,000 --> 00:04:23,000
443
+ Of course we'll have a detailed discussion later.
444
+
445
+ 112
446
+ 00:04:23,000 --> 00:04:25,000
447
+ At this point, private simply means,
448
+
449
+ 113
450
+ 00:04:25,000 --> 00:04:28,000
451
+ this particular variable, which is age,
452
+
453
+ 114
454
+ 00:04:28,000 --> 00:04:31,000
455
+ is accessible only in the same class.
456
+
457
+ 115
458
+ 00:04:31,000 --> 00:04:32,000
459
+ Let me repeat:
460
+
461
+ 116
462
+ 00:04:32,000 --> 00:04:37,000
463
+ This age variable is accessible in the same class.
464
+
465
+ 117
466
+ 00:04:37,000 --> 00:04:39,000
467
+ The moment you make it private, it's private.
468
+
469
+ 118
470
+ 00:04:39,000 --> 00:04:41,000
471
+ No one from the outside world can use it.
472
+
473
+ 119
474
+ 00:04:41,000 --> 00:04:44,000
475
+ Of course I can use my data because that's private to me,
476
+
477
+ 120
478
+ 00:04:44,000 --> 00:04:46,000
479
+ but you can't access my data.
480
+
481
+ 121
482
+ 00:04:46,000 --> 00:04:49,000
483
+ Because that's private to me, right?
484
+
485
+ 122
486
+ 00:04:49,000 --> 00:04:51,000
487
+ The same thing can be done for the variable here.
488
+
489
+ 123
490
+ 00:04:51,000 --> 00:04:54,000
491
+ And if you observe the moment I do that,
492
+
493
+ 124
494
+ 00:04:54,000 --> 00:04:56,000
495
+ we got an error here.
496
+
497
+ 125
498
+ 00:04:56,000 --> 00:04:58,000
499
+ I mean of course vs code helps you that.
500
+
501
+ 126
502
+ 00:04:58,000 --> 00:05:02,000
503
+ VS code says, "Hey, this variable age is not visible."
504
+
505
+ 127
506
+ 00:05:02,000 --> 00:05:05,000
507
+ You know why it's not visible? Because it's private!
508
+
509
+ 128
510
+ 00:05:05,000 --> 00:05:09,000
511
+ Now going forward, this is what you have to do.
512
+
513
+ 129
514
+ 00:05:09,000 --> 00:05:12,000
515
+ Every time you create a instance variable, let me repeat.
516
+
517
+ 130
518
+ 00:05:12,000 --> 00:05:17,000
519
+ Every time you create a instance variable, make it private.
520
+
521
+ 131
522
+ 00:05:18,000 --> 00:05:20,000
523
+ No one from the outside world should be able to use it.
524
+
525
+ 132
526
+ 00:05:20,000 --> 00:05:23,000
527
+ Now you will say, "Hey, doing that,
528
+
529
+ 133
530
+ 00:05:23,000 --> 00:05:26,000
531
+ we are actually breaking all the purpose
532
+
533
+ 134
534
+ 00:05:26,000 --> 00:05:27,000
535
+ of building a software," right?
536
+
537
+ 135
538
+ 00:05:27,000 --> 00:05:29,000
539
+ If no one is able to access this data,
540
+
541
+ 136
542
+ 00:05:29,000 --> 00:05:31,000
543
+ then why we are even creating these variables?
544
+
545
+ 137
546
+ 00:05:31,000 --> 00:05:32,000
547
+ That's right.
548
+
549
+ 138
550
+ 00:05:32,000 --> 00:05:34,000
551
+ The reason why we are creating this variable
552
+
553
+ 139
554
+ 00:05:34,000 --> 00:05:35,000
555
+ is because we can store values
556
+
557
+ 140
558
+ 00:05:35,000 --> 00:05:37,000
559
+ and someone should be able to access them.
560
+
561
+ 141
562
+ 00:05:37,000 --> 00:05:41,000
563
+ They should be able to access them but not directly.
564
+
565
+ 142
566
+ 00:05:41,000 --> 00:05:44,000
567
+ So there should be some indirect way.
568
+
569
+ 143
570
+ 00:05:44,000 --> 00:05:45,000
571
+ Yeah, we have indirect way.
572
+
573
+ 144
574
+ 00:05:45,000 --> 00:05:47,000
575
+ So the way they should be able to access this data is
576
+
577
+ 145
578
+ 00:05:47,000 --> 00:05:49,000
579
+ with the help of methods.
580
+
581
+ 146
582
+ 00:05:49,000 --> 00:05:52,000
583
+ Example, let's say if you want to know my name, you have
584
+
585
+ 147
586
+ 00:05:52,000 --> 00:05:53,000
587
+ to ask for it
588
+
589
+ 148
590
+ 00:05:53,000 --> 00:05:57,000
591
+ and I will decide should I share that data with you or not?
592
+
593
+ 149
594
+ 00:05:57,000 --> 00:05:58,000
595
+ So if you say, "Hey, what's your name?"
596
+
597
+ 150
598
+ 00:05:58,000 --> 00:06:01,000
599
+ I will say, okay, I will ask my brain what's my name
600
+
601
+ 151
602
+ 00:06:01,000 --> 00:06:03,000
603
+ because most of the time I don't remember my own name.
604
+
605
+ 152
606
+ 00:06:03,000 --> 00:06:05,000
607
+ So I will say, hey, what's my name?
608
+
609
+ 153
610
+ 00:06:05,000 --> 00:06:07,000
611
+ My brain will say, "Okay, your name is Navin."
612
+
613
+ 154
614
+ 00:06:07,000 --> 00:06:09,000
615
+ And then from my methods, which is my mouth
616
+
617
+ 155
618
+ 00:06:09,000 --> 00:06:13,000
619
+ or by using my handwriting or by typing somewhere,
620
+
621
+ 156
622
+ 00:06:13,000 --> 00:06:16,000
623
+ there's a way I have to share that data with you, right?
624
+
625
+ 157
626
+ 00:06:16,000 --> 00:06:20,000
627
+ I have some methods, behavior, I can talk,
628
+
629
+ 158
630
+ 00:06:20,000 --> 00:06:21,000
631
+ I can write, I can type.
632
+
633
+ 159
634
+ 00:06:21,000 --> 00:06:24,000
635
+ Now using those behavior, I can share the information, okay?
636
+
637
+ 160
638
+ 00:06:24,000 --> 00:06:26,000
639
+ Not like anyone can just come to me,
640
+
641
+ 161
642
+ 00:06:26,000 --> 00:06:29,000
643
+ they will break my head and say, "Okay, I got the data."
644
+
645
+ 162
646
+ 00:06:29,000 --> 00:06:31,000
647
+ No, that's not how it should work.
648
+
649
+ 163
650
+ 00:06:31,000 --> 00:06:34,000
651
+ So how do I restrict it?
652
+
653
+ 164
654
+ 00:06:34,000 --> 00:06:35,000
655
+ So what we can do is we can make it private.
656
+
657
+ 165
658
+ 00:06:35,000 --> 00:06:37,000
659
+ We are restricting it.
660
+
661
+ 166
662
+ 00:06:37,000 --> 00:06:40,000
663
+ The only way to access them is with the help of methods.
664
+
665
+ 167
666
+ 00:06:40,000 --> 00:06:42,000
667
+ So what I can do is temporary,
668
+
669
+ 168
670
+ 00:06:42,000 --> 00:06:44,000
671
+ I will just come in these two sections
672
+
673
+ 169
674
+ 00:06:44,000 --> 00:06:48,000
675
+ and I will assign the value here itself and we can do that.
676
+
677
+ 170
678
+ 00:06:48,000 --> 00:06:49,000
679
+ I will say name is Navin,
680
+
681
+ 171
682
+ 00:06:49,000 --> 00:06:53,000
683
+ and then here coming back to public, I will say public,
684
+
685
+ 172
686
+ 00:06:53,000 --> 00:06:54,000
687
+ I want to get data.
688
+
689
+ 173
690
+ 00:06:54,000 --> 00:06:56,000
691
+ I want to say, "Hey, get age," okay?
692
+
693
+ 174
694
+ 00:06:56,000 --> 00:06:59,000
695
+ And of course you can use any method name, doesn't matter.
696
+
697
+ 175
698
+ 00:06:59,000 --> 00:07:03,000
699
+ But let's say get age and this will return a integer value.
700
+
701
+ 176
702
+ 00:07:03,000 --> 00:07:06,000
703
+ So I will say int here, and this will return.
704
+
705
+ 177
706
+ 00:07:06,000 --> 00:07:08,000
707
+ So this will basically return the age.
708
+
709
+ 178
710
+ 00:07:08,000 --> 00:07:11,000
711
+ Another question is, can I access age here?
712
+
713
+ 179
714
+ 00:07:11,000 --> 00:07:13,000
715
+ And the answer is yes you can.
716
+
717
+ 180
718
+ 00:07:13,000 --> 00:07:16,000
719
+ You can access the age variable inside a method
720
+
721
+ 181
722
+ 00:07:16,000 --> 00:07:17,000
723
+ of a same class.
724
+
725
+ 182
726
+ 00:07:17,000 --> 00:07:19,000
727
+ That's right.
728
+
729
+ 183
730
+ 00:07:19,000 --> 00:07:22,000
731
+ This getAge is defined in the same class,
732
+
733
+ 184
734
+ 00:07:22,000 --> 00:07:24,000
735
+ that's why you are able to access that.
736
+
737
+ 185
738
+ 00:07:24,000 --> 00:07:26,000
739
+ And if you see age here or name here,
740
+
741
+ 186
742
+ 00:07:26,000 --> 00:07:29,000
743
+ so we are trying to get the data of another class,
744
+
745
+ 187
746
+ 00:07:29,000 --> 00:07:33,000
747
+ demo and Human, they are two different classes.
748
+
749
+ 188
750
+ 00:07:33,000 --> 00:07:34,000
751
+ Okay, makes sense now.
752
+
753
+ 189
754
+ 00:07:34,000 --> 00:07:36,000
755
+ Now we can also do it for the name.
756
+
757
+ 190
758
+ 00:07:36,000 --> 00:07:39,000
759
+ So for the name I will say public string getName
760
+
761
+ 191
762
+ 00:07:40,000 --> 00:07:44,000
763
+ and this will basically return a name.
764
+
765
+ 192
766
+ 00:07:44,000 --> 00:07:48,000
767
+ Okay? So we got two methods, get age and get name.
768
+
769
+ 193
770
+ 00:07:48,000 --> 00:07:50,000
771
+ And then we are returning the age and name.
772
+
773
+ 194
774
+ 00:07:50,000 --> 00:07:54,000
775
+ Now if someone wants to fetch it, I can simply say,
776
+
777
+ 195
778
+ 00:07:54,000 --> 00:07:56,000
779
+ "Hey, don't call name, that will not work."
780
+
781
+ 196
782
+ 00:07:56,000 --> 00:07:58,000
783
+ Because name is a variable, this is private.
784
+
785
+ 197
786
+ 00:07:58,000 --> 00:08:02,000
787
+ You can access the methods, you can say obj.getName
788
+
789
+ 198
790
+ 00:08:02,000 --> 00:08:04,000
791
+ That's how you can fetch a value.
792
+
793
+ 199
794
+ 00:08:04,000 --> 00:08:06,000
795
+ Of course you can also fetch the age.
796
+
797
+ 200
798
+ 00:08:06,000 --> 00:08:09,000
799
+ What I can do is I can just say, plus I can give a colon
800
+
801
+ 201
802
+ 00:08:09,000 --> 00:08:12,000
803
+ in between and I can say obj.getAge
804
+
805
+ 202
806
+ 00:08:12,000 --> 00:08:13,000
807
+ Okay?
808
+
809
+ 203
810
+ 00:08:13,000 --> 00:08:17,000
811
+ Now I think we should be able to access it.
812
+
813
+ 204
814
+ 00:08:17,000 --> 00:08:20,000
815
+ Let's try and compile, run.
816
+
817
+ 205
818
+ 00:08:20,000 --> 00:08:21,000
819
+ Oh it's working. Can you see that?
820
+
821
+ 206
822
+ 00:08:21,000 --> 00:08:23,000
823
+ We got Navin and 11.
824
+
825
+ 207
826
+ 00:08:23,000 --> 00:08:27,000
827
+ So the point remember is every time you create a variable
828
+
829
+ 208
830
+ 00:08:27,000 --> 00:08:30,000
831
+ which is private, we are making sure that it is restricted.
832
+
833
+ 209
834
+ 00:08:30,000 --> 00:08:33,000
835
+ No one from the outside world should be able to use it.
836
+
837
+ 210
838
+ 00:08:33,000 --> 00:08:36,000
839
+ So this age variable, this name variable will be used
840
+
841
+ 211
842
+ 00:08:36,000 --> 00:08:38,000
843
+ by their own methods.
844
+
845
+ 212
846
+ 00:08:38,000 --> 00:08:40,000
847
+ That actually makes some sense.
848
+
849
+ 213
850
+ 00:08:40,000 --> 00:08:43,000
851
+ But there's one little problem here.
852
+
853
+ 214
854
+ 00:08:43,000 --> 00:08:44,000
855
+ What if I want to assign the value?
856
+
857
+ 215
858
+ 00:08:44,000 --> 00:08:48,000
859
+ What if I don't specify the value here? Cut and cut.
860
+
861
+ 216
862
+ 00:08:48,000 --> 00:08:49,000
863
+ Let's say we have the variables,
864
+
865
+ 217
866
+ 00:08:49,000 --> 00:08:51,000
867
+ but I don't assign the value.
868
+
869
+ 218
870
+ 00:08:51,000 --> 00:08:53,000
871
+ Now of course, if you don't assign the value,
872
+
873
+ 219
874
+ 00:08:53,000 --> 00:08:56,000
875
+ default value will be zero and a null string.
876
+
877
+ 220
878
+ 00:08:56,000 --> 00:08:58,000
879
+ But how do I set the value?
880
+
881
+ 221
882
+ 00:08:58,000 --> 00:09:02,000
883
+ Now for getting the data we have said get,
884
+
885
+ 222
886
+ 00:09:02,000 --> 00:09:04,000
887
+ for setting data, can we say set?
888
+
889
+ 223
890
+ 00:09:04,000 --> 00:09:05,000
891
+ Let's try.
892
+
893
+ 224
894
+ 00:09:05,000 --> 00:09:07,000
895
+ So here for age, I will say public.
896
+
897
+ 225
898
+ 00:09:07,000 --> 00:09:08,000
899
+ Now when you are setting the value,
900
+
901
+ 226
902
+ 00:09:08,000 --> 00:09:10,000
903
+ you're not getting in return something, right?
904
+
905
+ 227
906
+ 00:09:10,000 --> 00:09:14,000
907
+ So you will say void and you will say setAge. Okay?
908
+
909
+ 228
910
+ 00:09:14,000 --> 00:09:16,000
911
+ Now it's just that when you are setting the age, you have
912
+
913
+ 229
914
+ 00:09:16,000 --> 00:09:19,000
915
+ to ask, "Hey, what is a value?"
916
+
917
+ 230
918
+ 00:09:19,000 --> 00:09:22,000
919
+ So maybe you can also accept a value here,
920
+
921
+ 231
922
+ 00:09:22,000 --> 00:09:24,000
923
+ maybe I can say A right?
924
+
925
+ 232
926
+ 00:09:24,000 --> 00:09:29,000
927
+ And then here I can say age is equal to A.
928
+
929
+ 233
930
+ 00:09:29,000 --> 00:09:30,000
931
+ Now what I mean by that is
932
+
933
+ 234
934
+ 00:09:30,000 --> 00:09:33,000
935
+ of course you have a method which is accepting a value,
936
+
937
+ 235
938
+ 00:09:33,000 --> 00:09:35,000
939
+ assigning that to age, but how it'll work?
940
+
941
+ 236
942
+ 00:09:35,000 --> 00:09:37,000
943
+ So let's come back here, which the portion
944
+
945
+ 237
946
+ 00:09:37,000 --> 00:09:38,000
947
+ which we have commented,
948
+
949
+ 238
950
+ 00:09:38,000 --> 00:09:39,000
951
+ I want to set the age, right?
952
+
953
+ 239
954
+ 00:09:39,000 --> 00:09:41,000
955
+ So instead of setting the age to the variable,
956
+
957
+ 240
958
+ 00:09:41,000 --> 00:09:44,000
959
+ I can say obj.setAge
960
+
961
+ 241
962
+ 00:09:44,000 --> 00:09:46,000
963
+ We are using a method now, not the variable.
964
+
965
+ 242
966
+ 00:09:46,000 --> 00:09:50,000
967
+ And in this particular bracket you can pass the argument.
968
+
969
+ 243
970
+ 00:09:50,000 --> 00:09:52,000
971
+ And let's say the age is 30.
972
+
973
+ 244
974
+ 00:09:52,000 --> 00:09:54,000
975
+ So now we are passing the value.
976
+
977
+ 245
978
+ 00:09:54,000 --> 00:09:57,000
979
+ Now this value will be assigned to this A
980
+
981
+ 246
982
+ 00:09:57,000 --> 00:10:00,000
983
+ and from A, this will be assigned to age.
984
+
985
+ 247
986
+ 00:10:00,000 --> 00:10:02,000
987
+ Can we do the same thing for string?
988
+
989
+ 248
990
+ 00:10:02,000 --> 00:10:06,000
991
+ Let's try, I'll say public void setName
992
+
993
+ 249
994
+ 00:10:06,000 --> 00:10:09,000
995
+ And of course we have to also accept the name.
996
+
997
+ 250
998
+ 00:10:09,000 --> 00:10:11,000
999
+ But what's the format of name?
1000
+
1001
+ 251
1002
+ 00:10:11,000 --> 00:10:14,000
1003
+ String name I will say N this time.
1004
+
1005
+ 252
1006
+ 00:10:14,000 --> 00:10:18,000
1007
+ And here I can say name is equal to N.
1008
+
1009
+ 253
1010
+ 00:10:18,000 --> 00:10:21,000
1011
+ So whatever value you pass, will be assigned to this n
1012
+
1013
+ 254
1014
+ 00:10:21,000 --> 00:10:24,000
1015
+ and from N it'll be assigned to name.
1016
+
1017
+ 255
1018
+ 00:10:24,000 --> 00:10:26,000
1019
+ Now the same thing need to be changed here.
1020
+
1021
+ 256
1022
+ 00:10:26,000 --> 00:10:28,000
1023
+ So I will just cut this part
1024
+
1025
+ 257
1026
+ 00:10:28,000 --> 00:10:29,000
1027
+ and I will say cut this part as well.
1028
+
1029
+ 258
1030
+ 00:10:29,000 --> 00:10:31,000
1031
+ I will say set name.
1032
+
1033
+ 259
1034
+ 00:10:31,000 --> 00:10:34,000
1035
+ And in the double codes I will pass the name.
1036
+
1037
+ 260
1038
+ 00:10:34,000 --> 00:10:36,000
1039
+ And the name here is Navin.
1040
+
1041
+ 261
1042
+ 00:10:36,000 --> 00:10:38,000
1043
+ Or maybe I'll use a different name
1044
+
1045
+ 262
1046
+ 00:10:38,000 --> 00:10:39,000
1047
+ this time I will say Reddy.
1048
+
1049
+ 263
1050
+ 00:10:39,000 --> 00:10:40,000
1051
+ Okay?
1052
+
1053
+ 264
1054
+ 00:10:40,000 --> 00:10:43,000
1055
+ And now I will just come back here, clear the screen,
1056
+
1057
+ 265
1058
+ 00:10:43,000 --> 00:10:45,000
1059
+ compile, run.
1060
+
1061
+ 266
1062
+ 00:10:45,000 --> 00:10:48,000
1063
+ Now you see that we got Reddy and 30.
1064
+
1065
+ 267
1066
+ 00:10:48,000 --> 00:10:50,000
1067
+ So what we are doing is we are assigning the value
1068
+
1069
+ 268
1070
+ 00:10:50,000 --> 00:10:52,000
1071
+ with the help of methods here
1072
+
1073
+ 269
1074
+ 00:10:52,000 --> 00:10:56,000
1075
+ and we are getting the value with the help of methods here.
1076
+
1077
+ 270
1078
+ 00:10:56,000 --> 00:10:58,000
1079
+ So that's how we can access this data.
1080
+
1081
+ 271
1082
+ 00:10:58,000 --> 00:11:02,000
1083
+ Now what we are doing is we are making your variable private
1084
+
1085
+ 272
1086
+ 00:11:02,000 --> 00:11:04,000
1087
+ and then the only way to access them is
1088
+
1089
+ 273
1090
+ 00:11:04,000 --> 00:11:05,000
1091
+ with the help of methods, right?
1092
+
1093
+ 274
1094
+ 00:11:05,000 --> 00:11:08,000
1095
+ So basically we are binding our data with the methods.
1096
+
1097
+ 275
1098
+ 00:11:08,000 --> 00:11:11,000
1099
+ The only way to access that data is with methods.
1100
+
1101
+ 276
1102
+ 00:11:11,000 --> 00:11:13,000
1103
+ So no one from the outside world can use
1104
+
1105
+ 277
1106
+ 00:11:13,000 --> 00:11:14,000
1107
+ your variables directly.
1108
+
1109
+ 278
1110
+ 00:11:14,000 --> 00:11:17,000
1111
+ So somewhere we are encapsulating the data and methods
1112
+
1113
+ 279
1114
+ 00:11:17,000 --> 00:11:19,000
1115
+ and that is Encapsulation.
1116
+
1117
+ 280
1118
+ 00:11:19,000 --> 00:11:21,000
1119
+ Okay? Simple stuff, right?
1120
+
1121
+ 281
1122
+ 00:11:21,000 --> 00:11:24,000
1123
+ So yeah, that's it from this video.
1124
+
1125
+ 282
1126
+ 00:11:24,000 --> 00:11:26,000
1127
+ Let's try to understand this more.
1128
+
1129
+ 283
1130
+ 00:11:26,000 --> 00:11:28,000
1131
+ What is this get and set methods?
1132
+
1133
+ 284
1134
+ 00:11:28,000 --> 00:11:30,000
1135
+ Can we use different names
1136
+
1137
+ 285
1138
+ 00:11:30,000 --> 00:11:32,000
1139
+ or only this name will work?
1140
+
1141
+ 286
1142
+ 00:11:32,000 --> 00:11:34,000
1143
+ That we'll discuss in the next video.
1144
+
02 - Core Java/044 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/045 Getters and setters_en.srt ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:02,000
3
+ (gentle music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: Let's try to understand what these methods are
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:08,000
11
+ or can we change the name?
12
+
13
+ 4
14
+ 00:00:08,000 --> 00:00:11,000
15
+ So getAge, setAge makes sense,
16
+
17
+ 5
18
+ 00:00:11,000 --> 00:00:13,000
19
+ but can we use some other names?
20
+
21
+ 6
22
+ 00:00:13,000 --> 00:00:14,000
23
+ Actually, we can.
24
+
25
+ 7
26
+ 00:00:14,000 --> 00:00:16,000
27
+ Instead of saying getAge, we can say abc,
28
+
29
+ 8
30
+ 00:00:16,000 --> 00:00:18,000
31
+ and setAge, we can say xyz.
32
+
33
+ 9
34
+ 00:00:18,000 --> 00:00:20,000
35
+ We can do that, okay? There's no harm in that.
36
+
37
+ 10
38
+ 00:00:20,000 --> 00:00:21,000
39
+ The only thing is when you call these methods,
40
+
41
+ 11
42
+ 00:00:21,000 --> 00:00:23,000
43
+ of course you have to change the name.
44
+
45
+ 12
46
+ 00:00:23,000 --> 00:00:25,000
47
+ I will say this is xyz,
48
+
49
+ 13
50
+ 00:00:25,000 --> 00:00:28,000
51
+ so when you set the value, you have to call xyz,
52
+
53
+ 14
54
+ 00:00:28,000 --> 00:00:31,000
55
+ and then when you fetch the value, you have to say abc,
56
+
57
+ 15
58
+ 00:00:31,000 --> 00:00:32,000
59
+ and it surely works.
60
+
61
+ 16
62
+ 00:00:32,000 --> 00:00:36,000
63
+ If I try to compile this and run,
64
+
65
+ 17
66
+ 00:00:36,000 --> 00:00:37,000
67
+ you can see it works.
68
+
69
+ 18
70
+ 00:00:37,000 --> 00:00:39,000
71
+ Now, the problem with abc and xyz or any name
72
+
73
+ 19
74
+ 00:00:39,000 --> 00:00:44,000
75
+ is your method name should define what is your intention.
76
+
77
+ 20
78
+ 00:00:44,000 --> 00:00:46,000
79
+ Because most of the time it's not just about writing code,
80
+
81
+ 21
82
+ 00:00:46,000 --> 00:00:47,000
83
+ it's also about reading code.
84
+
85
+ 22
86
+ 00:00:47,000 --> 00:00:49,000
87
+ When you write a code once,
88
+
89
+ 23
90
+ 00:00:49,000 --> 00:00:51,000
91
+ it will be read by multiple people
92
+
93
+ 24
94
+ 00:00:51,000 --> 00:00:53,000
95
+ in the entire lifetime of a software.
96
+
97
+ 25
98
+ 00:00:53,000 --> 00:00:54,000
99
+ Why not use proper words
100
+
101
+ 26
102
+ 00:00:54,000 --> 00:00:56,000
103
+ which explains what that method is doing?
104
+
105
+ 27
106
+ 00:00:56,000 --> 00:00:58,000
107
+ So instead of saying abc,
108
+
109
+ 28
110
+ 00:00:58,000 --> 00:01:00,000
111
+ if I say getAge,
112
+
113
+ 29
114
+ 00:01:00,000 --> 00:01:01,000
115
+ it is actually makes sense, right?
116
+
117
+ 30
118
+ 00:01:01,000 --> 00:01:04,000
119
+ It is much more readable what you're doing there, right?
120
+
121
+ 31
122
+ 00:01:04,000 --> 00:01:06,000
123
+ And as I mentioned before,
124
+
125
+ 32
126
+ 00:01:06,000 --> 00:01:08,000
127
+ it is not a compulsion to use the same name.
128
+
129
+ 33
130
+ 00:01:08,000 --> 00:01:12,000
131
+ But then as a Java developer, we have adopted this standard.
132
+
133
+ 34
134
+ 00:01:12,000 --> 00:01:15,000
135
+ Whenever you want to get the value of a variable,
136
+
137
+ 35
138
+ 00:01:15,000 --> 00:01:17,000
139
+ the method name would be get space,
140
+
141
+ 36
142
+ 00:01:17,000 --> 00:01:18,000
143
+ the other variable name,
144
+
145
+ 37
146
+ 00:01:18,000 --> 00:01:19,000
147
+ the variable name, which is age.
148
+
149
+ 38
150
+ 00:01:19,000 --> 00:01:20,000
151
+ To set the value,
152
+
153
+ 39
154
+ 00:01:20,000 --> 00:01:22,000
155
+ you will say set and you will use the variable name,
156
+
157
+ 40
158
+ 00:01:22,000 --> 00:01:24,000
159
+ which is age, okay?
160
+
161
+ 41
162
+ 00:01:24,000 --> 00:01:25,000
163
+ So, that's how we can use this.
164
+
165
+ 42
166
+ 00:01:25,000 --> 00:01:27,000
167
+ So, this is called a getter.
168
+
169
+ 43
170
+ 00:01:27,000 --> 00:01:29,000
171
+ So for the variable user, this is a getter.
172
+
173
+ 44
174
+ 00:01:29,000 --> 00:01:32,000
175
+ And when you want to set the value,
176
+
177
+ 45
178
+ 00:01:32,000 --> 00:01:34,000
179
+ so the method is called setter.
180
+
181
+ 46
182
+ 00:01:34,000 --> 00:01:38,000
183
+ So, we can say that those are getters and setters.
184
+
185
+ 47
186
+ 00:01:38,000 --> 00:01:40,000
187
+ In fact, the beauty is
188
+
189
+ 48
190
+ 00:01:40,000 --> 00:01:42,000
191
+ if I delete the entire part,
192
+
193
+ 49
194
+ 00:01:42,000 --> 00:01:43,000
195
+ okay, let me just do that.
196
+
197
+ 50
198
+ 00:01:43,000 --> 00:01:46,000
199
+ I know we need to type that once again.
200
+
201
+ 51
202
+ 00:01:46,000 --> 00:01:47,000
203
+ Actually, you don't.
204
+
205
+ 52
206
+ 00:01:47,000 --> 00:01:49,000
207
+ Most of the IDEs have this amazing feature.
208
+
209
+ 53
210
+ 00:01:49,000 --> 00:01:52,000
211
+ You can just right-click and there's a option of source.
212
+
213
+ 54
214
+ 00:01:52,000 --> 00:01:55,000
215
+ In fact, it doesn't matter which IDE you're using,
216
+
217
+ 55
218
+ 00:01:55,000 --> 00:01:56,000
219
+ you will see the option of source
220
+
221
+ 56
222
+ 00:01:56,000 --> 00:01:58,000
223
+ or insert code, something like this.
224
+
225
+ 57
226
+ 00:01:58,000 --> 00:02:01,000
227
+ So it will say Source Action, what do you want?
228
+
229
+ 58
230
+ 00:02:01,000 --> 00:02:03,000
231
+ You want to get,
232
+
233
+ 59
234
+ 00:02:03,000 --> 00:02:07,000
235
+ you have to say Generate Getters and Setters for me.
236
+
237
+ 60
238
+ 00:02:07,000 --> 00:02:08,000
239
+ Click on that.
240
+
241
+ 61
242
+ 00:02:08,000 --> 00:02:09,000
243
+ For both the variables,
244
+
245
+ 62
246
+ 00:02:09,000 --> 00:02:11,000
247
+ and click on OK.
248
+
249
+ 63
250
+ 00:02:11,000 --> 00:02:14,000
251
+ You can see it will generate the methods for you
252
+
253
+ 64
254
+ 00:02:14,000 --> 00:02:16,000
255
+ and you see that variable names, it's same.
256
+
257
+ 65
258
+ 00:02:16,000 --> 00:02:21,000
259
+ getAge, setAge, and then we got getName, setName, okay?
260
+
261
+ 66
262
+ 00:02:21,000 --> 00:02:23,000
263
+ And those are called getters and setters.
264
+
265
+ 67
266
+ 00:02:23,000 --> 00:02:25,000
267
+ And of course, there is no compulsion
268
+
269
+ 68
270
+ 00:02:25,000 --> 00:02:26,000
271
+ to have both the methods.
272
+
273
+ 69
274
+ 00:02:26,000 --> 00:02:28,000
275
+ You can only have getName.
276
+
277
+ 70
278
+ 00:02:28,000 --> 00:02:30,000
279
+ You don't want to have setName, that's your choice.
280
+
281
+ 71
282
+ 00:02:30,000 --> 00:02:32,000
283
+ There's no compulsion that there should be both.
284
+
285
+ 72
286
+ 00:02:32,000 --> 00:02:34,000
287
+ It depends upon you how you want to implement it.
288
+
289
+ 73
290
+ 00:02:34,000 --> 00:02:38,000
291
+ For this example, I want to assign value to age and name.
292
+
293
+ 74
294
+ 00:02:38,000 --> 00:02:39,000
295
+ I want to get the values as well
296
+
297
+ 75
298
+ 00:02:39,000 --> 00:02:41,000
299
+ and that's why I'm using this tool.
300
+
301
+ 76
302
+ 00:02:41,000 --> 00:02:42,000
303
+ So only thing is for every variable,
304
+
305
+ 77
306
+ 00:02:42,000 --> 00:02:45,000
307
+ you need two methods, getters and setters, okay?
308
+
309
+ 78
310
+ 00:02:45,000 --> 00:02:46,000
311
+ So yeah, that's it.
312
+
313
+ 79
314
+ 00:02:46,000 --> 00:02:48,000
315
+ But there's only one issue now.
316
+
317
+ 80
318
+ 00:02:48,000 --> 00:02:50,000
319
+ If I use the code which is given by the IDE,
320
+
321
+ 81
322
+ 00:02:50,000 --> 00:02:53,000
323
+ you can see this new keyword here, we got this.
324
+
325
+ 82
326
+ 00:02:53,000 --> 00:02:56,000
327
+ What is this? So, let's talk about this in the next video.
328
+
02 - Core Java/045 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/046 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/046 This keyword_en.srt ADDED
@@ -0,0 +1,908 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (calm piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: In this video, let's talk about this
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:07,000
11
+ because in the previous video,
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:08,000
15
+ we were doing something
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:10,000
19
+ and then suddenly we got this keyword.
20
+
21
+ 6
22
+ 00:00:10,000 --> 00:00:13,000
23
+ So it's important now to talk about this keyword here.
24
+
25
+ 7
26
+ 00:00:13,000 --> 00:00:15,000
27
+ Now, what I will do is I will just remove this,
28
+
29
+ 8
30
+ 00:00:15,000 --> 00:00:19,000
31
+ or I will just change this variable name back to A and N.
32
+
33
+ 9
34
+ 00:00:19,000 --> 00:00:24,000
35
+ And of course, here, we have to say A and N, right?
36
+
37
+ 10
38
+ 00:00:24,000 --> 00:00:26,000
39
+ And let me remove this keyword from here
40
+
41
+ 11
42
+ 00:00:26,000 --> 00:00:27,000
43
+ just to see if this works.
44
+
45
+ 12
46
+ 00:00:27,000 --> 00:00:29,000
47
+ Now, if I remove this keyword from there
48
+
49
+ 13
50
+ 00:00:29,000 --> 00:00:31,000
51
+ and you find on this code compile, okay,
52
+
53
+ 14
54
+ 00:00:31,000 --> 00:00:34,000
55
+ there is some problem with the variable names.
56
+
57
+ 15
58
+ 00:00:34,000 --> 00:00:36,000
59
+ I think we are still calling X, Y, Z,
60
+
61
+ 16
62
+ 00:00:36,000 --> 00:00:37,000
63
+ so it should be setAge.
64
+
65
+ 17
66
+ 00:00:38,000 --> 00:00:39,000
67
+ And we are still calling A, B, C.
68
+
69
+ 18
70
+ 00:00:39,000 --> 00:00:42,000
71
+ It should be getAge, the same thing
72
+
73
+ 19
74
+ 00:00:42,000 --> 00:00:44,000
75
+ which we have done in the previous video.
76
+
77
+ 20
78
+ 00:00:44,000 --> 00:00:47,000
79
+ Okay, so if I save this and if I go back and compile,
80
+
81
+ 21
82
+ 00:00:47,000 --> 00:00:51,000
83
+ so compile, done, running, done,
84
+
85
+ 22
86
+ 00:00:51,000 --> 00:00:54,000
87
+ so you can see we got the values right?
88
+
89
+ 23
90
+ 00:00:54,000 --> 00:00:56,000
91
+ Now, the thing is when you talk about this variable like age
92
+
93
+ 24
94
+ 00:00:56,000 --> 00:00:58,000
95
+ and when you are passing a here,
96
+
97
+ 25
98
+ 00:00:58,000 --> 00:01:00,000
99
+ we are using two different variables right?
100
+
101
+ 26
102
+ 00:01:00,000 --> 00:01:04,000
103
+ Now, the point to remember here is this a variable here
104
+
105
+ 27
106
+ 00:01:04,000 --> 00:01:05,000
107
+ is a local variable.
108
+
109
+ 28
110
+ 00:01:05,000 --> 00:01:09,000
111
+ This age variable here is a instance variable, right?
112
+
113
+ 29
114
+ 00:01:09,000 --> 00:01:11,000
115
+ If you want to understand that with a diagram,
116
+
117
+ 30
118
+ 00:01:11,000 --> 00:01:13,000
119
+ you can just go back here.
120
+
121
+ 31
122
+ 00:01:13,000 --> 00:01:15,000
123
+ We have a stack memory, remember?
124
+
125
+ 32
126
+ 00:01:15,000 --> 00:01:17,000
127
+ We have talked about stack and heap.
128
+
129
+ 33
130
+ 00:01:17,000 --> 00:01:19,000
131
+ So we got a stack here and then we got heap here.
132
+
133
+ 34
134
+ 00:01:19,000 --> 00:01:22,000
135
+ Now, the moment you create the human object,
136
+
137
+ 35
138
+ 00:01:22,000 --> 00:01:23,000
139
+ we got this object here, Human.
140
+
141
+ 36
142
+ 00:01:23,000 --> 00:01:25,000
143
+ So in this, we have a Human object
144
+
145
+ 37
146
+ 00:01:25,000 --> 00:01:29,000
147
+ and of course, it will have some address, let's say, 101.
148
+
149
+ 38
150
+ 00:01:29,000 --> 00:01:32,000
151
+ So we got obj and the address is 101.
152
+
153
+ 39
154
+ 00:01:32,000 --> 00:01:33,000
155
+ That's the first object we got.
156
+
157
+ 40
158
+ 00:01:33,000 --> 00:01:37,000
159
+ And there's a link here which we cannot ignore.
160
+
161
+ 41
162
+ 00:01:37,000 --> 00:01:39,000
163
+ And then we have some more variables.
164
+
165
+ 42
166
+ 00:01:39,000 --> 00:01:41,000
167
+ You can see if you execute.
168
+
169
+ 43
170
+ 00:01:41,000 --> 00:01:44,000
171
+ And of course, this was my main stack.
172
+
173
+ 44
174
+ 00:01:45,000 --> 00:01:47,000
175
+ Now, we are executing which method?
176
+
177
+ 45
178
+ 00:01:47,000 --> 00:01:52,000
179
+ So if you say setAge, we are executing setAge method, right?
180
+
181
+ 46
182
+ 00:01:52,000 --> 00:01:54,000
183
+ Now, setAge will have its own stack here.
184
+
185
+ 47
186
+ 00:01:54,000 --> 00:01:56,000
187
+ Let's say, we have a setAge stack here.
188
+
189
+ 48
190
+ 00:01:56,000 --> 00:01:57,000
191
+ You know what?
192
+
193
+ 49
194
+ 00:01:57,000 --> 00:01:59,000
195
+ I just have to zoom it a bit
196
+
197
+ 50
198
+ 00:01:59,000 --> 00:02:01,000
199
+ and here, let me create segments.
200
+
201
+ 51
202
+ 00:02:01,000 --> 00:02:04,000
203
+ So we got multiple segments here
204
+
205
+ 52
206
+ 00:02:04,000 --> 00:02:05,000
207
+ and of course, this will be linked
208
+
209
+ 53
210
+ 00:02:05,000 --> 00:02:08,000
211
+ with this particular variable here.
212
+
213
+ 54
214
+ 00:02:08,000 --> 00:02:10,000
215
+ And don't you think this box
216
+
217
+ 55
218
+ 00:02:10,000 --> 00:02:12,000
219
+ which is address 101 is an object of Human?
220
+
221
+ 56
222
+ 00:02:12,000 --> 00:02:14,000
223
+ So it will also have the instance variable.
224
+
225
+ 57
226
+ 00:02:14,000 --> 00:02:15,000
227
+ How many instance variable we have.
228
+
229
+ 58
230
+ 00:02:15,000 --> 00:02:20,000
231
+ We have age and name. So we got age and we got name here.
232
+
233
+ 59
234
+ 00:02:20,000 --> 00:02:23,000
235
+ Now, if you look at the setAge, now setAge,
236
+
237
+ 60
238
+ 00:02:23,000 --> 00:02:27,000
239
+ this particular stack is of setAge.
240
+
241
+ 61
242
+ 00:02:27,000 --> 00:02:28,000
243
+ Every method will have its own stack.
244
+
245
+ 62
246
+ 00:02:28,000 --> 00:02:31,000
247
+ And in this, we got a variable called a,
248
+
249
+ 63
250
+ 00:02:31,000 --> 00:02:34,000
251
+ and the value for a which we are passing is study.
252
+
253
+ 64
254
+ 00:02:34,000 --> 00:02:36,000
255
+ So we got 30 here, okay?
256
+
257
+ 65
258
+ 00:02:36,000 --> 00:02:40,000
259
+ And then the same value 30, we are assigning to age.
260
+
261
+ 66
262
+ 00:02:40,000 --> 00:02:43,000
263
+ That means we are changing this variable,
264
+
265
+ 67
266
+ 00:02:43,000 --> 00:02:45,000
267
+ and we are assigning a value which is 30 there,
268
+
269
+ 68
270
+ 00:02:45,000 --> 00:02:47,000
271
+ if that makes sense, okay?
272
+
273
+ 69
274
+ 00:02:47,000 --> 00:02:50,000
275
+ So both the value for a and age is 30.
276
+
277
+ 70
278
+ 00:02:50,000 --> 00:02:52,000
279
+ And that's why when you fetch data,
280
+
281
+ 71
282
+ 00:02:52,000 --> 00:02:56,000
283
+ when you say getAge, it will return the value of age
284
+
285
+ 72
286
+ 00:02:56,000 --> 00:02:59,000
287
+ in the object which is 30, in this case.
288
+
289
+ 73
290
+ 00:02:59,000 --> 00:03:00,000
291
+ And that is perfectly working.
292
+
293
+ 74
294
+ 00:03:00,000 --> 00:03:03,000
295
+ Now, the problem is what if I just make
296
+
297
+ 75
298
+ 00:03:03,000 --> 00:03:08,000
299
+ this particular variable age as age, I mean, a as age?
300
+
301
+ 76
302
+ 00:03:08,000 --> 00:03:10,000
303
+ Now, what I want is I want my local variable
304
+
305
+ 77
306
+ 00:03:10,000 --> 00:03:13,000
307
+ and my instance variable both
308
+
309
+ 78
310
+ 00:03:13,000 --> 00:03:16,000
311
+ to have the same variable name.
312
+
313
+ 79
314
+ 00:03:16,000 --> 00:03:19,000
315
+ What do you mean by that is if I remove this a from here,
316
+
317
+ 80
318
+ 00:03:19,000 --> 00:03:22,000
319
+ the variable name here will be age.
320
+
321
+ 81
322
+ 00:03:22,000 --> 00:03:25,000
323
+ So both the variable name, the local variable
324
+
325
+ 82
326
+ 00:03:25,000 --> 00:03:28,000
327
+ and the instance variable have the same name,
328
+
329
+ 83
330
+ 00:03:28,000 --> 00:03:30,000
331
+ then it should work, right?
332
+
333
+ 84
334
+ 00:03:30,000 --> 00:03:31,000
335
+ What we're trying to do is
336
+
337
+ 85
338
+ 00:03:31,000 --> 00:03:33,000
339
+ the age variable will get 30 here.
340
+
341
+ 86
342
+ 00:03:33,000 --> 00:03:37,000
343
+ So of course, in this stack, we got 30.
344
+
345
+ 87
346
+ 00:03:37,000 --> 00:03:40,000
347
+ And if you see we are assigning age is equal to age.
348
+
349
+ 88
350
+ 00:03:40,000 --> 00:03:42,000
351
+ So I'm expecting that this age will get the value
352
+
353
+ 89
354
+ 00:03:42,000 --> 00:03:45,000
355
+ from this particular age. It should work, right?
356
+
357
+ 90
358
+ 00:03:45,000 --> 00:03:46,000
359
+ Let's try.
360
+
361
+ 91
362
+ 00:03:46,000 --> 00:03:51,000
363
+ If I go back to my code and compile and run,
364
+
365
+ 92
366
+ 00:03:51,000 --> 00:03:52,000
367
+ oh, can you see that?
368
+
369
+ 93
370
+ 00:03:52,000 --> 00:03:54,000
371
+ The value for age is still zero.
372
+
373
+ 94
374
+ 00:03:54,000 --> 00:03:56,000
375
+ That means the assignment which we are assuming
376
+
377
+ 95
378
+ 00:03:56,000 --> 00:03:58,000
379
+ that it will be 30, it is still zero.
380
+
381
+ 96
382
+ 00:03:58,000 --> 00:04:03,000
383
+ Why? The reason is if we look at line number 11,
384
+
385
+ 97
386
+ 00:04:03,000 --> 00:04:07,000
387
+ and if you see it, we are saying age is equal to age.
388
+
389
+ 98
390
+ 00:04:07,000 --> 00:04:10,000
391
+ The problem is by default, now see,
392
+
393
+ 99
394
+ 00:04:10,000 --> 00:04:12,000
395
+ this age can be local variable.
396
+
397
+ 100
398
+ 00:04:12,000 --> 00:04:14,000
399
+ This age can be instance variable, right?
400
+
401
+ 101
402
+ 00:04:14,000 --> 00:04:17,000
403
+ Because the names are same. So can we do this?
404
+
405
+ 102
406
+ 00:04:17,000 --> 00:04:21,000
407
+ Can we say it is possible that
408
+
409
+ 103
410
+ 00:04:21,000 --> 00:04:24,000
411
+ the age here is actually a local variable?
412
+
413
+ 104
414
+ 00:04:24,000 --> 00:04:26,000
415
+ It is also possible that
416
+
417
+ 105
418
+ 00:04:26,000 --> 00:04:29,000
419
+ the age is assigning value to itself.
420
+
421
+ 106
422
+ 00:04:29,000 --> 00:04:32,000
423
+ Maybe this age is not even a instance variable.
424
+
425
+ 107
426
+ 00:04:32,000 --> 00:04:35,000
427
+ That means this age is assigning value to itself
428
+
429
+ 108
430
+ 00:04:35,000 --> 00:04:39,000
431
+ and this age here, which we have created,
432
+
433
+ 109
434
+ 00:04:39,000 --> 00:04:41,000
435
+ it is still zero.
436
+
437
+ 110
438
+ 00:04:41,000 --> 00:04:42,000
439
+ And that's why we are getting zero.
440
+
441
+ 111
442
+ 00:04:42,000 --> 00:04:44,000
443
+ How do we solve this problem?
444
+
445
+ 112
446
+ 00:04:44,000 --> 00:04:46,000
447
+ So somewhere we have to mention, hey, you know?
448
+
449
+ 113
450
+ 00:04:46,000 --> 00:04:48,000
451
+ This particular age here, this is not a local variable.
452
+
453
+ 114
454
+ 00:04:48,000 --> 00:04:49,000
455
+ This is an instance variable.
456
+
457
+ 115
458
+ 00:04:49,000 --> 00:04:52,000
459
+ So remember this point, the preference will always give,
460
+
461
+ 116
462
+ 00:04:52,000 --> 00:04:54,000
463
+ always be given to local variable.
464
+
465
+ 117
466
+ 00:04:54,000 --> 00:04:58,000
467
+ So in case of confusion, it is always the local variable.
468
+
469
+ 118
470
+ 00:04:58,000 --> 00:04:59,000
471
+ We have to mention by some way,
472
+
473
+ 119
474
+ 00:04:59,000 --> 00:05:01,000
475
+ hey, this is not local variable.
476
+
477
+ 120
478
+ 00:05:01,000 --> 00:05:03,000
479
+ That's an instance variable. How do you mention that?
480
+
481
+ 121
482
+ 00:05:03,000 --> 00:05:05,000
483
+ So in order to say that's an instance variable,
484
+
485
+ 122
486
+ 00:05:05,000 --> 00:05:06,000
487
+ can we do this?
488
+
489
+ 123
490
+ 00:05:06,000 --> 00:05:08,000
491
+ Can we say Human?
492
+
493
+ 124
494
+ 00:05:08,000 --> 00:05:11,000
495
+ Can we create object here itself, obj1 = new Human?
496
+
497
+ 125
498
+ 00:05:11,000 --> 00:05:14,000
499
+ And then we can say obj1.age.
500
+
501
+ 126
502
+ 00:05:14,000 --> 00:05:16,000
503
+ Now, what we are doing is we are saying
504
+
505
+ 127
506
+ 00:05:16,000 --> 00:05:19,000
507
+ this age is a instance variable.
508
+
509
+ 128
510
+ 00:05:19,000 --> 00:05:20,000
511
+ And you might be thinking,
512
+
513
+ 129
514
+ 00:05:20,000 --> 00:05:24,000
515
+ hey, how can we use age with a object?
516
+
517
+ 130
518
+ 00:05:24,000 --> 00:05:24,000
519
+ See, we can't do that
520
+
521
+ 131
522
+ 00:05:24,000 --> 00:05:27,000
523
+ because we are in the same class, okay?
524
+
525
+ 132
526
+ 00:05:27,000 --> 00:05:28,000
527
+ We were not able to do that here
528
+
529
+ 133
530
+ 00:05:28,000 --> 00:05:30,000
531
+ because we were in different class.
532
+
533
+ 134
534
+ 00:05:30,000 --> 00:05:33,000
535
+ But again, the problem is we are saying this age is instance
536
+
537
+ 135
538
+ 00:05:33,000 --> 00:05:35,000
539
+ and this age is local, this should work.
540
+
541
+ 136
542
+ 00:05:35,000 --> 00:05:36,000
543
+ Let's see if this is a problem
544
+
545
+ 137
546
+ 00:05:36,000 --> 00:05:38,000
547
+ or we have solved the problem.
548
+
549
+ 138
550
+ 00:05:38,000 --> 00:05:42,000
551
+ Let's run this. Oh, it is still zero. What is happening?
552
+
553
+ 139
554
+ 00:05:42,000 --> 00:05:44,000
555
+ Let's try to understand more.
556
+
557
+ 140
558
+ 00:05:44,000 --> 00:05:46,000
559
+ Now, when you execute this setAge method,
560
+
561
+ 141
562
+ 00:05:46,000 --> 00:05:49,000
563
+ what we are doing is we are creating a new object.
564
+
565
+ 142
566
+ 00:05:49,000 --> 00:05:50,000
567
+ Oh, that's the issue.
568
+
569
+ 143
570
+ 00:05:50,000 --> 00:05:54,000
571
+ We are basically creating a new object.
572
+
573
+ 144
574
+ 00:05:54,000 --> 00:05:57,000
575
+ Okay, how do we solve this problem?
576
+
577
+ 145
578
+ 00:05:57,000 --> 00:05:58,000
579
+ We don't want to get new object
580
+
581
+ 146
582
+ 00:05:58,000 --> 00:06:00,000
583
+ because the moment you create new object,
584
+
585
+ 147
586
+ 00:06:00,000 --> 00:06:02,000
587
+ what will happen here is it will create a new object,
588
+
589
+ 148
590
+ 00:06:02,000 --> 00:06:04,000
591
+ let's say 103.
592
+
593
+ 149
594
+ 00:06:04,000 --> 00:06:05,000
595
+ And this will have,
596
+
597
+ 150
598
+ 00:06:05,000 --> 00:06:08,000
599
+ this will also have age equal to name equal to,
600
+
601
+ 151
602
+ 00:06:08,000 --> 00:06:10,000
603
+ and what value you're assigning here?
604
+
605
+ 152
606
+ 00:06:10,000 --> 00:06:11,000
607
+ You're assigning value which is 30.
608
+
609
+ 153
610
+ 00:06:11,000 --> 00:06:16,000
611
+ And then here in this setAge, you will create obj1
612
+
613
+ 154
614
+ 00:06:17,000 --> 00:06:20,000
615
+ which will have the address 103 and there's a link here.
616
+
617
+ 155
618
+ 00:06:20,000 --> 00:06:22,000
619
+ So the value which you are changing is
620
+
621
+ 156
622
+ 00:06:22,000 --> 00:06:25,000
623
+ of this age, not this one.
624
+
625
+ 157
626
+ 00:06:25,000 --> 00:06:28,000
627
+ We want to assign the value to this particular age.
628
+
629
+ 158
630
+ 00:06:28,000 --> 00:06:31,000
631
+ That means creating a new object is not a good idea.
632
+
633
+ 159
634
+ 00:06:31,000 --> 00:06:34,000
635
+ Okay, how do I clear this? Let's remove this.
636
+
637
+ 160
638
+ 00:06:34,000 --> 00:06:35,000
639
+ In fact, you know? this is a problem.
640
+
641
+ 161
642
+ 00:06:35,000 --> 00:06:37,000
643
+ This is creating a new object.
644
+
645
+ 162
646
+ 00:06:37,000 --> 00:06:39,000
647
+ Okay, if I don't want to get a new object,
648
+
649
+ 163
650
+ 00:06:39,000 --> 00:06:42,000
651
+ how do I access this obj?
652
+
653
+ 164
654
+ 00:06:42,000 --> 00:06:44,000
655
+ Oh, I got an idea here.
656
+
657
+ 165
658
+ 00:06:44,000 --> 00:06:49,000
659
+ What if with this 30, if I can pass the object itself,
660
+
661
+ 166
662
+ 00:06:49,000 --> 00:06:50,000
663
+ can we, will it solve the problem?
664
+
665
+ 167
666
+ 00:06:50,000 --> 00:06:54,000
667
+ With 30, if you can pass this particular object,
668
+
669
+ 168
670
+ 00:06:54,000 --> 00:06:58,000
671
+ and we can accept the object here.
672
+
673
+ 169
674
+ 00:06:58,000 --> 00:07:02,000
675
+ What type of object it is? It is human, Human obj.
676
+
677
+ 170
678
+ 00:07:02,000 --> 00:07:05,000
679
+ And then here, we can simply assign the value.
680
+
681
+ 171
682
+ 00:07:05,000 --> 00:07:08,000
683
+ So what I'm doing is if you observe correctly,
684
+
685
+ 172
686
+ 00:07:08,000 --> 00:07:10,000
687
+ we are not creating a new object.
688
+
689
+ 173
690
+ 00:07:10,000 --> 00:07:14,000
691
+ We are basically passing the reference of the old object.
692
+
693
+ 174
694
+ 00:07:14,000 --> 00:07:19,000
695
+ So here, it will be not 103, it will be 101, okay?
696
+
697
+ 175
698
+ 00:07:21,000 --> 00:07:24,000
699
+ So this obj1 here will get the address 101,
700
+
701
+ 176
702
+ 00:07:24,000 --> 00:07:27,000
703
+ and we can simply say obj1.age.
704
+
705
+ 177
706
+ 00:07:27,000 --> 00:07:29,000
707
+ And now, we are not referring to this address,
708
+
709
+ 178
710
+ 00:07:29,000 --> 00:07:31,000
711
+ we are referring to this address.
712
+
713
+ 179
714
+ 00:07:31,000 --> 00:07:33,000
715
+ So we can change the age value 30,
716
+
717
+ 180
718
+ 00:07:33,000 --> 00:07:35,000
719
+ and let's see if this works.
720
+
721
+ 181
722
+ 00:07:35,000 --> 00:07:36,000
723
+ I hope this will work.
724
+
725
+ 182
726
+ 00:07:36,000 --> 00:07:40,000
727
+ Compile, sorry, compile, run.
728
+
729
+ 183
730
+ 00:07:40,000 --> 00:07:43,000
731
+ Oh, it is working. It is working.
732
+
733
+ 184
734
+ 00:07:43,000 --> 00:07:44,000
735
+ So basically, the important thing
736
+
737
+ 185
738
+ 00:07:44,000 --> 00:07:45,000
739
+ is how do you differentiate
740
+
741
+ 186
742
+ 00:07:45,000 --> 00:07:48,000
743
+ between instance variable and a local variable?
744
+
745
+ 187
746
+ 00:07:48,000 --> 00:07:51,000
747
+ It's bypassing the object itself,
748
+
749
+ 188
750
+ 00:07:51,000 --> 00:07:54,000
751
+ but there's one little problem here.
752
+
753
+ 189
754
+ 00:07:54,000 --> 00:07:59,000
755
+ The problem is if you read this line, it says obj.setAge
756
+
757
+ 190
758
+ 00:07:59,000 --> 00:08:02,000
759
+ and then you're passing the obj object as well.
760
+
761
+ 191
762
+ 00:08:02,000 --> 00:08:03,000
763
+ Why we have to do this?
764
+
765
+ 192
766
+ 00:08:03,000 --> 00:08:08,000
767
+ Why you have to mention obj two times. Now, Java knows this.
768
+
769
+ 193
770
+ 00:08:08,000 --> 00:08:10,000
771
+ Java says, hey, you don't worry.
772
+
773
+ 194
774
+ 00:08:10,000 --> 00:08:11,000
775
+ Why you have to pass the object two times?
776
+
777
+ 195
778
+ 00:08:11,000 --> 00:08:14,000
779
+ I mean, you're calling the method by using the object.
780
+
781
+ 196
782
+ 00:08:14,000 --> 00:08:15,000
783
+ You are also passing the object.
784
+
785
+ 197
786
+ 00:08:15,000 --> 00:08:18,000
787
+ Don't do that. Don't pass the object.
788
+
789
+ 198
790
+ 00:08:18,000 --> 00:08:20,000
791
+ By default, I will give you this obj.
792
+
793
+ 199
794
+ 00:08:20,000 --> 00:08:22,000
795
+ You don't even have to accept this obj.
796
+
797
+ 200
798
+ 00:08:22,000 --> 00:08:25,000
799
+ What if Java says, hey don't worry.
800
+
801
+ 201
802
+ 00:08:25,000 --> 00:08:27,000
803
+ Don't create the object, don't pass the object.
804
+
805
+ 202
806
+ 00:08:27,000 --> 00:08:30,000
807
+ I will give you the object and that object, my friend,
808
+
809
+ 203
810
+ 00:08:30,000 --> 00:08:33,000
811
+ in fact, you know, when we had Human here,
812
+
813
+ 204
814
+ 00:08:33,000 --> 00:08:35,000
815
+ we don't even need this Human line here.
816
+
817
+ 205
818
+ 00:08:35,000 --> 00:08:38,000
819
+ We could have removed that and even obj would've worked.
820
+
821
+ 206
822
+ 00:08:38,000 --> 00:08:41,000
823
+ So your Java says, hey, why do you even use this obj
824
+
825
+ 207
826
+ 00:08:41,000 --> 00:08:43,000
827
+ when we can simply use this?
828
+
829
+ 208
830
+ 00:08:43,000 --> 00:08:48,000
831
+ Now, this is a keyword which represents the current object.
832
+
833
+ 209
834
+ 00:08:48,000 --> 00:08:50,000
835
+ Now, when I say current object, what it means?
836
+
837
+ 210
838
+ 00:08:50,000 --> 00:08:53,000
839
+ The object which is calling the method.
840
+
841
+ 211
842
+ 00:08:53,000 --> 00:08:56,000
843
+ SetAge is called OBJ, which is this object.
844
+
845
+ 212
846
+ 00:08:57,000 --> 00:09:00,000
847
+ Here in this method, we can actually use that object
848
+
849
+ 213
850
+ 00:09:00,000 --> 00:09:02,000
851
+ with the help of this keyword.
852
+
853
+ 214
854
+ 00:09:02,000 --> 00:09:04,000
855
+ So this refers to the current object
856
+
857
+ 215
858
+ 00:09:04,000 --> 00:09:06,000
859
+ who is calling the setAge.
860
+
861
+ 216
862
+ 00:09:06,000 --> 00:09:08,000
863
+ I hope that makes sense.
864
+
865
+ 217
866
+ 00:09:08,000 --> 00:09:10,000
867
+ So from this point, we are always
868
+
869
+ 218
870
+ 00:09:10,000 --> 00:09:13,000
871
+ going to use this which represent the current object, okay?
872
+
873
+ 219
874
+ 00:09:13,000 --> 00:09:18,000
875
+ So here as well, instead of using name or n,
876
+
877
+ 220
878
+ 00:09:18,000 --> 00:09:20,000
879
+ I should have used name.
880
+
881
+ 221
882
+ 00:09:20,000 --> 00:09:21,000
883
+ The only thing is we have to refer
884
+
885
+ 222
886
+ 00:09:21,000 --> 00:09:24,000
887
+ the part, first name here is this.name,
888
+
889
+ 223
890
+ 00:09:24,000 --> 00:09:26,000
891
+ which is the object itself.
892
+
893
+ 224
894
+ 00:09:26,000 --> 00:09:27,000
895
+ The current object.
896
+
897
+ 225
898
+ 00:09:27,000 --> 00:09:30,000
899
+ I hope this all this thing have made sense.
900
+
901
+ 226
902
+ 00:09:30,000 --> 00:09:32,000
903
+ This is what this keyword is.
904
+
905
+ 227
906
+ 00:09:32,000 --> 00:09:34,000
907
+ And yeah, that's it from this video.
908
+
02 - Core Java/047 Constructor_en.srt ADDED
@@ -0,0 +1,736 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: In this video, we'll talk about constructors.
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:07,000
11
+ Now what are constructors?
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:09,000
15
+ Now look at this example here, which is of human.
16
+
17
+ 5
18
+ 00:00:09,000 --> 00:00:10,000
19
+ Now when you talk about human,
20
+
21
+ 6
22
+ 00:00:10,000 --> 00:00:11,000
23
+ we have some variables, right?
24
+
25
+ 7
26
+ 00:00:11,000 --> 00:00:13,000
27
+ Of course, when you talk about this two variables,
28
+
29
+ 8
30
+ 00:00:13,000 --> 00:00:15,000
31
+ these are instance variable,
32
+
33
+ 9
34
+ 00:00:15,000 --> 00:00:18,000
35
+ and then we have seen in the image as well.
36
+
37
+ 10
38
+ 00:00:18,000 --> 00:00:20,000
39
+ Basically when you create an object example in this,
40
+
41
+ 11
42
+ 00:00:20,000 --> 00:00:23,000
43
+ we are just creating one object,
44
+
45
+ 12
46
+ 00:00:23,000 --> 00:00:26,000
47
+ and that object is getting created inside the heap memory.
48
+
49
+ 13
50
+ 00:00:26,000 --> 00:00:28,000
51
+ You can see this is the object we got.
52
+
53
+ 14
54
+ 00:00:28,000 --> 00:00:29,000
55
+ And of course with that object we have assigned
56
+
57
+ 15
58
+ 00:00:29,000 --> 00:00:31,000
59
+ the value for the age,
60
+
61
+ 16
62
+ 00:00:31,000 --> 00:00:32,000
63
+ we have assigned the value for the name as well,
64
+
65
+ 17
66
+ 00:00:32,000 --> 00:00:35,000
67
+ which is ready. But I'm not return it here,
68
+
69
+ 18
70
+ 00:00:35,000 --> 00:00:38,000
71
+ but we know that the object is created.
72
+
73
+ 19
74
+ 00:00:38,000 --> 00:00:41,000
75
+ Now the thing is, when you create the object,
76
+
77
+ 20
78
+ 00:00:41,000 --> 00:00:43,000
79
+ if you observe the line number 29,
80
+
81
+ 21
82
+ 00:00:43,000 --> 00:00:46,000
83
+ on this line, when you create the object, what happens?
84
+
85
+ 22
86
+ 00:00:46,000 --> 00:00:48,000
87
+ When you create the object in the heap memory,
88
+
89
+ 23
90
+ 00:00:48,000 --> 00:00:50,000
91
+ it will just create a blank object.
92
+
93
+ 24
94
+ 00:00:50,000 --> 00:00:54,000
95
+ Example. If I try to remove this, if I keep it empty,
96
+
97
+ 25
98
+ 00:00:54,000 --> 00:00:57,000
99
+ it will create a object with a value.
100
+
101
+ 26
102
+ 00:00:57,000 --> 00:00:58,000
103
+ So the value would be,
104
+
105
+ 27
106
+ 00:00:58,000 --> 00:01:01,000
107
+ I mean it will have a variable which is age,
108
+
109
+ 28
110
+ 00:01:01,000 --> 00:01:02,000
111
+ and the value will be zero,
112
+
113
+ 29
114
+ 00:01:02,000 --> 00:01:05,000
115
+ and it will have a variable called a name,
116
+
117
+ 30
118
+ 00:01:05,000 --> 00:01:07,000
119
+ and the value will be null, right?
120
+
121
+ 31
122
+ 00:01:07,000 --> 00:01:10,000
123
+ I will just try to print those things.
124
+
125
+ 32
126
+ 00:01:10,000 --> 00:01:13,000
127
+ What if I do is, I will just print the same statement
128
+
129
+ 33
130
+ 00:01:13,000 --> 00:01:15,000
131
+ before assigning the value, right?
132
+
133
+ 34
134
+ 00:01:15,000 --> 00:01:18,000
135
+ So I'm printing it here and I will command this section.
136
+
137
+ 35
138
+ 00:01:18,000 --> 00:01:19,000
139
+ So that's how you command, right?
140
+
141
+ 36
142
+ 00:01:19,000 --> 00:01:21,000
143
+ I don't want this time to be executed.
144
+
145
+ 37
146
+ 00:01:21,000 --> 00:01:24,000
147
+ And now if I go back here and
148
+
149
+ 38
150
+ 00:01:24,000 --> 00:01:25,000
151
+ compile
152
+
153
+ 39
154
+ 00:01:25,000 --> 00:01:27,000
155
+ and run, you can see we got null.
156
+
157
+ 40
158
+ 00:01:27,000 --> 00:01:30,000
159
+ Null basically is when you don't have the data assigned
160
+
161
+ 41
162
+ 00:01:30,000 --> 00:01:31,000
163
+ to object type.
164
+
165
+ 42
166
+ 00:01:31,000 --> 00:01:34,000
167
+ That's right. String is an object type.
168
+
169
+ 43
170
+ 00:01:34,000 --> 00:01:36,000
171
+ We'll discuss about string later in detail.
172
+
173
+ 44
174
+ 00:01:36,000 --> 00:01:38,000
175
+ As of now, just remember by default
176
+
177
+ 45
178
+ 00:01:38,000 --> 00:01:40,000
179
+ the value for string is null,
180
+
181
+ 46
182
+ 00:01:40,000 --> 00:01:42,000
183
+ and the default value for integer is zero.
184
+
185
+ 47
186
+ 00:01:42,000 --> 00:01:46,000
187
+ Okay, that means if you don't assign this values,
188
+
189
+ 48
190
+ 00:01:46,000 --> 00:01:48,000
191
+ there will be default values.
192
+
193
+ 49
194
+ 00:01:48,000 --> 00:01:49,000
195
+ What I want here is,
196
+
197
+ 50
198
+ 00:01:49,000 --> 00:01:52,000
199
+ of course there is a way you can assign the values later.
200
+
201
+ 51
202
+ 00:01:52,000 --> 00:01:54,000
203
+ But what if I want to assign the value
204
+
205
+ 52
206
+ 00:01:54,000 --> 00:01:57,000
207
+ when the object is created?
208
+
209
+ 53
210
+ 00:01:57,000 --> 00:01:59,000
211
+ That's right, on this line itself,
212
+
213
+ 54
214
+ 00:01:59,000 --> 00:02:00,000
215
+ I want to assign the value.
216
+
217
+ 55
218
+ 00:02:00,000 --> 00:02:02,000
219
+ That means the moment I get the object,
220
+
221
+ 56
222
+ 00:02:02,000 --> 00:02:03,000
223
+ I don't want to have a null value,
224
+
225
+ 57
226
+ 00:02:03,000 --> 00:02:05,000
227
+ I want to have some default values.
228
+
229
+ 58
230
+ 00:02:05,000 --> 00:02:08,000
231
+ Example, let's say by default every object created,
232
+
233
+ 59
234
+ 00:02:08,000 --> 00:02:09,000
235
+ the name should be something else.
236
+
237
+ 60
238
+ 00:02:09,000 --> 00:02:12,000
239
+ The name should be, let's say Babu or something else.
240
+
241
+ 61
242
+ 00:02:12,000 --> 00:02:14,000
243
+ I'm not sure, but can we have a default name?
244
+
245
+ 62
246
+ 00:02:14,000 --> 00:02:16,000
247
+ Can we have a default age?
248
+
249
+ 63
250
+ 00:02:16,000 --> 00:02:18,000
251
+ So let's say for my application,
252
+
253
+ 64
254
+ 00:02:18,000 --> 00:02:20,000
255
+ this application can be used only by those people
256
+
257
+ 65
258
+ 00:02:20,000 --> 00:02:23,000
259
+ who are 12 and about.
260
+
261
+ 66
262
+ 00:02:23,000 --> 00:02:25,000
263
+ So I can simply say, hey, the minimum age for this is 12.
264
+
265
+ 67
266
+ 00:02:25,000 --> 00:02:28,000
267
+ So by default the value for the age should be 12.
268
+
269
+ 68
270
+ 00:02:28,000 --> 00:02:29,000
271
+ Can we do that?
272
+
273
+ 69
274
+ 00:02:30,000 --> 00:02:32,000
275
+ So how do we achieve that?
276
+
277
+ 70
278
+ 00:02:32,000 --> 00:02:34,000
279
+ Of course, we can assign the values here,
280
+
281
+ 71
282
+ 00:02:34,000 --> 00:02:37,000
283
+ or we can use something called a constructor.
284
+
285
+ 72
286
+ 00:02:37,000 --> 00:02:39,000
287
+ Now how a constructor looks like,
288
+
289
+ 73
290
+ 00:02:39,000 --> 00:02:43,000
291
+ so a constructor looks like a method itself.
292
+
293
+ 74
294
+ 00:02:43,000 --> 00:02:46,000
295
+ Let me repeat. A constructor looks like a method itself.
296
+
297
+ 75
298
+ 00:02:46,000 --> 00:02:48,000
299
+ That means a constructor will have a name,
300
+
301
+ 76
302
+ 00:02:48,000 --> 00:02:50,000
303
+ a constructor will have the round brackets.
304
+
305
+ 77
306
+ 00:02:50,000 --> 00:02:53,000
307
+ Example, if we talk about methods here we have a name
308
+
309
+ 78
310
+ 00:02:53,000 --> 00:02:56,000
311
+ and we have a round bracket in the same way
312
+
313
+ 79
314
+ 00:02:56,000 --> 00:02:59,000
315
+ for the constructor as well, we have to use that.
316
+
317
+ 80
318
+ 00:02:59,000 --> 00:03:01,000
319
+ So what I will do is I will say public.
320
+
321
+ 81
322
+ 00:03:01,000 --> 00:03:03,000
323
+ Now the only changes in the constructor,
324
+
325
+ 82
326
+ 00:03:03,000 --> 00:03:06,000
327
+ you don't specify the written type.
328
+
329
+ 83
330
+ 00:03:06,000 --> 00:03:09,000
331
+ Okay? So we can directly mention the constructor name here,
332
+
333
+ 84
334
+ 00:03:09,000 --> 00:03:12,000
335
+ but what should be my constructor name?
336
+
337
+ 85
338
+ 00:03:12,000 --> 00:03:15,000
339
+ Now there's a compulsion that your constructor name
340
+
341
+ 86
342
+ 00:03:15,000 --> 00:03:17,000
343
+ should be same as your class name.
344
+
345
+ 87
346
+ 00:03:17,000 --> 00:03:19,000
347
+ So what is my class name? It's human.
348
+
349
+ 88
350
+ 00:03:19,000 --> 00:03:20,000
351
+ And then since it looks like a method,
352
+
353
+ 89
354
+ 00:03:20,000 --> 00:03:23,000
355
+ we can give a round bracket and we can open and close
356
+
357
+ 90
358
+ 00:03:23,000 --> 00:03:24,000
359
+ the curly brackets.
360
+
361
+ 91
362
+ 00:03:24,000 --> 00:03:27,000
363
+ Now one thing I wanted to mention, you can see
364
+
365
+ 92
366
+ 00:03:27,000 --> 00:03:29,000
367
+ with the curly packets are mentioned just I mean,
368
+
369
+ 93
370
+ 00:03:29,000 --> 00:03:31,000
371
+ for the opening brackets are just
372
+
373
+ 94
374
+ 00:03:31,000 --> 00:03:32,000
375
+ mentioned on the same line.
376
+
377
+ 95
378
+ 00:03:32,000 --> 00:03:35,000
379
+ And here the curly brackets are mentioned on the new line,
380
+
381
+ 96
382
+ 00:03:35,000 --> 00:03:36,000
383
+ both works.
384
+
385
+ 97
386
+ 00:03:36,000 --> 00:03:38,000
387
+ Some people prefer to use on the same line,
388
+
389
+ 98
390
+ 00:03:38,000 --> 00:03:40,000
391
+ some people prefer to use on next line.
392
+
393
+ 99
394
+ 00:03:40,000 --> 00:03:41,000
395
+ So anything works.
396
+
397
+ 100
398
+ 00:03:41,000 --> 00:03:44,000
399
+ Now in this constructor I can assign the values,
400
+
401
+ 101
402
+ 00:03:44,000 --> 00:03:46,000
403
+ but at this point let's not assign the value,
404
+
405
+ 102
406
+ 00:03:46,000 --> 00:03:49,000
407
+ I will just simply print the statement.
408
+
409
+ 103
410
+ 00:03:49,000 --> 00:03:54,000
411
+ I will say is sout, and here I will print in constructor.
412
+
413
+ 104
414
+ 00:03:54,000 --> 00:03:56,000
415
+ So you can see we are printing in constructor here.
416
+
417
+ 105
418
+ 00:03:56,000 --> 00:03:59,000
419
+ So that's our constructor.
420
+
421
+ 106
422
+ 00:03:59,000 --> 00:04:00,000
423
+ Okay, so let me repeat what is constructor?
424
+
425
+ 107
426
+ 00:04:00,000 --> 00:04:03,000
427
+ So constructor is a special method, that's right,
428
+
429
+ 108
430
+ 00:04:03,000 --> 00:04:05,000
431
+ because it looks like a method.
432
+
433
+ 109
434
+ 00:04:05,000 --> 00:04:06,000
435
+ It has the same name as a class name.
436
+
437
+ 110
438
+ 00:04:06,000 --> 00:04:08,000
439
+ So those are the rules you have to remember.
440
+
441
+ 111
442
+ 00:04:08,000 --> 00:04:11,000
443
+ The constructor will have the same name as a class name.
444
+
445
+ 112
446
+ 00:04:11,000 --> 00:04:13,000
447
+ A constructor never returns anything.
448
+
449
+ 113
450
+ 00:04:13,000 --> 00:04:15,000
451
+ You don't have to mention int, float,
452
+
453
+ 114
454
+ 00:04:15,000 --> 00:04:16,000
455
+ or string anything there.
456
+
457
+ 115
458
+ 00:04:16,000 --> 00:04:18,000
459
+ So just specify the access, which is public,
460
+
461
+ 116
462
+ 00:04:18,000 --> 00:04:21,000
463
+ and then mention the name, which is human.
464
+
465
+ 117
466
+ 00:04:21,000 --> 00:04:23,000
467
+ And in this you can do whatever you want.
468
+
469
+ 118
470
+ 00:04:23,000 --> 00:04:26,000
471
+ Okay, so I'm just printing in constructor.
472
+
473
+ 119
474
+ 00:04:26,000 --> 00:04:28,000
475
+ So let me just try and compile.
476
+
477
+ 120
478
+ 00:04:28,000 --> 00:04:30,000
479
+ So compilation done. There's no problem.
480
+
481
+ 121
482
+ 00:04:30,000 --> 00:04:34,000
483
+ When I done this code, one thing to observe, nowhere,
484
+
485
+ 122
486
+ 00:04:34,000 --> 00:04:36,000
487
+ see, when you talk about these methods like get age
488
+
489
+ 123
490
+ 00:04:36,000 --> 00:04:39,000
491
+ or set age, all these methods we have called them, right?
492
+
493
+ 124
494
+ 00:04:39,000 --> 00:04:41,000
495
+ So this is where you are calling them.
496
+
497
+ 125
498
+ 00:04:41,000 --> 00:04:44,000
499
+ Constructor, you can see we are not calling it,
500
+
501
+ 126
502
+ 00:04:44,000 --> 00:04:48,000
503
+ but still constructor will be called.
504
+
505
+ 127
506
+ 00:04:48,000 --> 00:04:50,000
507
+ Okay, so even if we don't call it, it will be called.
508
+
509
+ 128
510
+ 00:04:50,000 --> 00:04:51,000
511
+ Now when it will be called,
512
+
513
+ 129
514
+ 00:04:51,000 --> 00:04:53,000
515
+ every time you create an object,
516
+
517
+ 130
518
+ 00:04:53,000 --> 00:04:55,000
519
+ it will call the constructor.
520
+
521
+ 131
522
+ 00:04:55,000 --> 00:04:57,000
523
+ So every time you create the object,
524
+
525
+ 132
526
+ 00:04:57,000 --> 00:04:59,000
527
+ it will call the constructor.
528
+
529
+ 133
530
+ 00:04:59,000 --> 00:05:01,000
531
+ Example, let's say if I create two objects,
532
+
533
+ 134
534
+ 00:05:01,000 --> 00:05:02,000
535
+ I will just copy this line and paste it here.
536
+
537
+ 135
538
+ 00:05:02,000 --> 00:05:04,000
539
+ Of course, I should have a different name
540
+
541
+ 136
542
+ 00:05:04,000 --> 00:05:05,000
543
+ for the difference OBJ 1.
544
+
545
+ 137
546
+ 00:05:05,000 --> 00:05:08,000
547
+ Now you can see we have two objects.
548
+
549
+ 138
550
+ 00:05:08,000 --> 00:05:09,000
551
+ Now, when you say you have two objects,
552
+
553
+ 139
554
+ 00:05:09,000 --> 00:05:12,000
555
+ and if I try to compile and run this,
556
+
557
+ 140
558
+ 00:05:12,000 --> 00:05:14,000
559
+ you can see we got in constructor two times.
560
+
561
+ 141
562
+ 00:05:14,000 --> 00:05:17,000
563
+ So every time you create a new object,
564
+
565
+ 142
566
+ 00:05:17,000 --> 00:05:19,000
567
+ it will create a constructor,
568
+
569
+ 143
570
+ 00:05:19,000 --> 00:05:20,000
571
+ or it will call the constructor.
572
+
573
+ 144
574
+ 00:05:20,000 --> 00:05:22,000
575
+ Okay, if that makes sense.
576
+
577
+ 145
578
+ 00:05:22,000 --> 00:05:24,000
579
+ What we can do is if we can remove this line
580
+
581
+ 146
582
+ 00:05:24,000 --> 00:05:28,000
583
+ and I can assign the values, I can say age is equal to 12,
584
+
585
+ 147
586
+ 00:05:28,000 --> 00:05:32,000
587
+ and name is equal to let's say by default, John,
588
+
589
+ 148
590
+ 00:05:32,000 --> 00:05:35,000
591
+ of course you can have any name, but let's say John.
592
+
593
+ 149
594
+ 00:05:35,000 --> 00:05:40,000
595
+ Now in this case I can see if this values are assigned.
596
+
597
+ 150
598
+ 00:05:40,000 --> 00:05:42,000
599
+ What I can also do is I can just command this section.
600
+
601
+ 151
602
+ 00:05:42,000 --> 00:05:44,000
603
+ Let's say I'm not assigning the values.
604
+
605
+ 152
606
+ 00:05:44,000 --> 00:05:46,000
607
+ Let's see what are default values?
608
+
609
+ 153
610
+ 00:05:46,000 --> 00:05:48,000
611
+ Compile, run, you can see we got John and 12.
612
+
613
+ 154
614
+ 00:05:48,000 --> 00:05:52,000
615
+ So by default you assign this value.
616
+
617
+ 155
618
+ 00:05:52,000 --> 00:05:55,000
619
+ Okay, so this is where constructors are helpful.
620
+
621
+ 156
622
+ 00:05:55,000 --> 00:05:56,000
623
+ Now, you might be thinking,
624
+
625
+ 157
626
+ 00:05:56,000 --> 00:05:59,000
627
+ hey, we can assign values here itself, right?
628
+
629
+ 158
630
+ 00:05:59,000 --> 00:06:02,000
631
+ See, there's a idea, there's a standards which we follow,
632
+
633
+ 159
634
+ 00:06:02,000 --> 00:06:05,000
635
+ whenever you want to perform any operation,
636
+
637
+ 160
638
+ 00:06:05,000 --> 00:06:07,000
639
+ always do that in a method.
640
+
641
+ 161
642
+ 00:06:07,000 --> 00:06:11,000
643
+ Don't openly do it in the statement like here,
644
+
645
+ 162
646
+ 00:06:11,000 --> 00:06:13,000
647
+ if you want to perform some operation, like assignment,
648
+
649
+ 163
650
+ 00:06:13,000 --> 00:06:16,000
651
+ or calculation, always doing the methods.
652
+
653
+ 164
654
+ 00:06:16,000 --> 00:06:19,000
655
+ And constructor is like method, right?
656
+
657
+ 165
658
+ 00:06:19,000 --> 00:06:20,000
659
+ So you can assign the values here.
660
+
661
+ 166
662
+ 00:06:20,000 --> 00:06:23,000
663
+ There's no harm in terms of compilation.
664
+
665
+ 167
666
+ 00:06:23,000 --> 00:06:25,000
667
+ You can assign the value here as well.
668
+
669
+ 168
670
+ 00:06:25,000 --> 00:06:27,000
671
+ But we have to follow standards, right?
672
+
673
+ 169
674
+ 00:06:27,000 --> 00:06:29,000
675
+ And also just try to think about something at once.
676
+
677
+ 170
678
+ 00:06:29,000 --> 00:06:32,000
679
+ Let's say you are trying to connect with a database.
680
+
681
+ 171
682
+ 00:06:32,000 --> 00:06:35,000
683
+ Now in that scenario, your application
684
+
685
+ 172
686
+ 00:06:35,000 --> 00:06:38,000
687
+ is trying to connect with our database or the network.
688
+
689
+ 173
690
+ 00:06:38,000 --> 00:06:40,000
691
+ You need that connection right?
692
+
693
+ 174
694
+ 00:06:40,000 --> 00:06:42,000
695
+ Now where you will write the connection?
696
+
697
+ 175
698
+ 00:06:42,000 --> 00:06:45,000
699
+ You can write the connections in the constructor.
700
+
701
+ 176
702
+ 00:06:45,000 --> 00:06:47,000
703
+ And that's why this becomes very important.
704
+
705
+ 177
706
+ 00:06:47,000 --> 00:06:48,000
707
+ Now, if you remember,
708
+
709
+ 178
710
+ 00:06:48,000 --> 00:06:50,000
711
+ we have also talked about method overloading.
712
+
713
+ 179
714
+ 00:06:50,000 --> 00:06:53,000
715
+ So when you have two methods with the same name
716
+
717
+ 180
718
+ 00:06:53,000 --> 00:06:54,000
719
+ but different parameters,
720
+
721
+ 181
722
+ 00:06:54,000 --> 00:06:56,000
723
+ those are called method overloading.
724
+
725
+ 182
726
+ 00:06:56,000 --> 00:07:00,000
727
+ Now can we do that in constructor? That's tricky, right?
728
+
729
+ 183
730
+ 00:07:00,000 --> 00:07:02,000
731
+ So let's discuss that in the next video.
732
+
733
+ 184
734
+ 00:07:02,000 --> 00:07:05,000
735
+ How do we achieve constructor overloading.
736
+
02 - Core Java/047 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/048 Default vs Parameterized Constructor_en.srt ADDED
@@ -0,0 +1,520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: Okay, so now we know what is constructor, right?
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:09,000
11
+ But what about this? I mean, can I pass the values here?
12
+
13
+ 4
14
+ 00:00:09,000 --> 00:00:12,000
15
+ What if I don't want to assign values like 12 and John?
16
+
17
+ 5
18
+ 00:00:12,000 --> 00:00:14,000
19
+ What if I want to customize it?
20
+
21
+ 6
22
+ 00:00:14,000 --> 00:00:17,000
23
+ So, what I want is every time I create the object,
24
+
25
+ 7
26
+ 00:00:17,000 --> 00:00:20,000
27
+ I should have an option of passing those values,
28
+
29
+ 8
30
+ 00:00:20,000 --> 00:00:22,000
31
+ not 12 and John every time.
32
+
33
+ 9
34
+ 00:00:22,000 --> 00:00:23,000
35
+ Can we do that?
36
+
37
+ 10
38
+ 00:00:23,000 --> 00:00:24,000
39
+ Of course, you can assign the values later
40
+
41
+ 11
42
+ 00:00:24,000 --> 00:00:26,000
43
+ with the help of site methods,
44
+
45
+ 12
46
+ 00:00:26,000 --> 00:00:29,000
47
+ but what if I have an idea where, hey, you know,
48
+
49
+ 13
50
+ 00:00:29,000 --> 00:00:31,000
51
+ I, okay, let's go with this object, as well,
52
+
53
+ 14
54
+ 00:00:31,000 --> 00:00:33,000
55
+ the second object.
56
+
57
+ 15
58
+ 00:00:33,000 --> 00:00:35,000
59
+ And in the second object, I want to pass the values.
60
+
61
+ 16
62
+ 00:00:35,000 --> 00:00:37,000
63
+ The first object, I want it to be default.
64
+
65
+ 17
66
+ 00:00:37,000 --> 00:00:40,000
67
+ The second object, I want the age to be, let's say 18.
68
+
69
+ 18
70
+ 00:00:40,000 --> 00:00:44,000
71
+ And the name should be let's say Navin. Can we do that?
72
+
73
+ 19
74
+ 00:00:44,000 --> 00:00:46,000
75
+ If you can see, this line is giving you error.
76
+
77
+ 20
78
+ 00:00:46,000 --> 00:00:49,000
79
+ It says, hey, you know you don't have a constructor
80
+
81
+ 21
82
+ 00:00:49,000 --> 00:00:51,000
83
+ which accepts two values,
84
+
85
+ 22
86
+ 00:00:51,000 --> 00:00:53,000
87
+ so those two values of type integer and string,
88
+
89
+ 23
90
+ 00:00:53,000 --> 00:00:54,000
91
+ you don't have it.
92
+
93
+ 24
94
+ 00:00:54,000 --> 00:00:56,000
95
+ And if you go up, actually, you don't have it.
96
+
97
+ 25
98
+ 00:00:56,000 --> 00:00:59,000
99
+ You don't have a constructor which takes two parameters.
100
+
101
+ 26
102
+ 00:00:59,000 --> 00:01:01,000
103
+ Can we do that? Let's try.
104
+
105
+ 27
106
+ 00:01:01,000 --> 00:01:03,000
107
+ So, I will say public Human,
108
+
109
+ 28
110
+ 00:01:03,000 --> 00:01:06,000
111
+ and I want this Human to take two parameters.
112
+
113
+ 29
114
+ 00:01:06,000 --> 00:01:11,000
115
+ So I will say int a, String name
116
+
117
+ 30
118
+ 00:01:11,000 --> 00:01:13,000
119
+ and then here, I can just come back
120
+
121
+ 31
122
+ 00:01:13,000 --> 00:01:15,000
123
+ and I can say age is equal to a.
124
+
125
+ 32
126
+ 00:01:15,000 --> 00:01:18,000
127
+ So, not the default value which I want to assign here.
128
+
129
+ 33
130
+ 00:01:18,000 --> 00:01:21,000
131
+ I want to assign the value which is sent by the main method.
132
+
133
+ 34
134
+ 00:01:21,000 --> 00:01:25,000
135
+ So, if you can see, we are passing 18 and Navin here, right?
136
+
137
+ 35
138
+ 00:01:25,000 --> 00:01:27,000
139
+ So I can just go back here.
140
+
141
+ 36
142
+ 00:01:27,000 --> 00:01:30,000
143
+ And age is equal to a. Name is equal to n.
144
+
145
+ 37
146
+ 00:01:30,000 --> 00:01:33,000
147
+ Now if you look at this particular constructor here,
148
+
149
+ 38
150
+ 00:01:33,000 --> 00:01:35,000
151
+ it is taking some parameter.
152
+
153
+ 39
154
+ 00:01:35,000 --> 00:01:38,000
155
+ So this constructor is called a parameterized constructor.
156
+
157
+ 40
158
+ 00:01:38,000 --> 00:01:40,000
159
+ Oh, I should say this is n.
160
+
161
+ 41
162
+ 00:01:40,000 --> 00:01:43,000
163
+ Now, what is the difference between normal constructor
164
+
165
+ 42
166
+ 00:01:43,000 --> 00:01:45,000
167
+ and a parameterized constructor is, in fact,
168
+
169
+ 43
170
+ 00:01:45,000 --> 00:01:47,000
171
+ this normal constructor is also called
172
+
173
+ 44
174
+ 00:01:47,000 --> 00:01:49,000
175
+ a default constructor.
176
+
177
+ 45
178
+ 00:01:49,000 --> 00:01:51,000
179
+ Now we'll discuss why this called default constructor.
180
+
181
+ 46
182
+ 00:01:51,000 --> 00:01:53,000
183
+ So, this is called a default constructor.
184
+
185
+ 47
186
+ 00:01:53,000 --> 00:01:56,000
187
+ This is called a parameterized constructor
188
+
189
+ 48
190
+ 00:01:56,000 --> 00:01:57,000
191
+ because we have parameters there.
192
+
193
+ 49
194
+ 00:01:57,000 --> 00:02:00,000
195
+ And whatever value you pass here will be assigned.
196
+
197
+ 50
198
+ 00:02:00,000 --> 00:02:01,000
199
+ Now, you can use both syntax.
200
+
201
+ 51
202
+ 00:02:01,000 --> 00:02:03,000
203
+ You can either create an object
204
+
205
+ 52
206
+ 00:02:03,000 --> 00:02:06,000
207
+ by not specifying any parameter or arguments,
208
+
209
+ 53
210
+ 00:02:06,000 --> 00:02:11,000
211
+ and you can create a object with the help of values,
212
+
213
+ 54
214
+ 00:02:11,000 --> 00:02:13,000
215
+ which we are passing it here.
216
+
217
+ 55
218
+ 00:02:13,000 --> 00:02:16,000
219
+ So, this is parameterized and this is default.
220
+
221
+ 56
222
+ 00:02:16,000 --> 00:02:17,000
223
+ Now what I will do just to explain this,
224
+
225
+ 57
226
+ 00:02:17,000 --> 00:02:20,000
227
+ is I will just copy the same line
228
+
229
+ 58
230
+ 00:02:20,000 --> 00:02:23,000
231
+ and I will print the values for obj1 this time,
232
+
233
+ 59
234
+ 00:02:23,000 --> 00:02:24,000
235
+ not for obj, obj1.
236
+
237
+ 60
238
+ 00:02:24,000 --> 00:02:26,000
239
+ So basically, we are printing both
240
+
241
+ 61
242
+ 00:02:26,000 --> 00:02:27,000
243
+ and let's see what the output is.
244
+
245
+ 62
246
+ 00:02:27,000 --> 00:02:29,000
247
+ Compile, run.
248
+
249
+ 63
250
+ 00:02:29,000 --> 00:02:32,000
251
+ You can see we got the first object, John : 12.
252
+
253
+ 64
254
+ 00:02:32,000 --> 00:02:33,000
255
+ The second object is not John and 12.
256
+
257
+ 65
258
+ 00:02:33,000 --> 00:02:35,000
259
+ It is Navin and 18
260
+
261
+ 66
262
+ 00:02:35,000 --> 00:02:36,000
263
+ because you are passing those values.
264
+
265
+ 67
266
+ 00:02:36,000 --> 00:02:38,000
267
+ Now what I will do this time and I will remove this part
268
+
269
+ 68
270
+ 00:02:38,000 --> 00:02:40,000
271
+ just to explain you something.
272
+
273
+ 69
274
+ 00:02:40,000 --> 00:02:42,000
275
+ See, when I mentioned that every time,
276
+
277
+ 70
278
+ 00:02:42,000 --> 00:02:44,000
279
+ let me just commend this section, as well.
280
+
281
+ 71
282
+ 00:02:44,000 --> 00:02:47,000
283
+ See, every time you create the object,
284
+
285
+ 72
286
+ 00:02:47,000 --> 00:02:50,000
287
+ it will call the constructor, right?
288
+
289
+ 73
290
+ 00:02:50,000 --> 00:02:52,000
291
+ But then if you see, I have removed the constructor.
292
+
293
+ 74
294
+ 00:02:52,000 --> 00:02:53,000
295
+ Will this work?
296
+
297
+ 75
298
+ 00:02:53,000 --> 00:02:55,000
299
+ And it was working before.
300
+
301
+ 76
302
+ 00:02:55,000 --> 00:02:56,000
303
+ Remember when we started this example of Human,
304
+
305
+ 77
306
+ 00:02:56,000 --> 00:02:58,000
307
+ we were not having any constructor.
308
+
309
+ 78
310
+ 00:02:58,000 --> 00:03:00,000
311
+ It was still working.
312
+
313
+ 79
314
+ 00:03:00,000 --> 00:03:03,000
315
+ At this point, your Java will say, hey, don't worry.
316
+
317
+ 80
318
+ 00:03:03,000 --> 00:03:05,000
319
+ If you don't mention constructor there,
320
+
321
+ 81
322
+ 00:03:05,000 --> 00:03:07,000
323
+ I will create a constructor for you.
324
+
325
+ 82
326
+ 00:03:07,000 --> 00:03:10,000
327
+ And that's why we say that's a default constructor.
328
+
329
+ 83
330
+ 00:03:10,000 --> 00:03:13,000
331
+ So behind the scene, you will get this constructor here,
332
+
333
+ 84
334
+ 00:03:13,000 --> 00:03:15,000
335
+ which is public Human.
336
+
337
+ 85
338
+ 00:03:15,000 --> 00:03:18,000
339
+ This is what you will get even if you don't mention, okay?
340
+
341
+ 86
342
+ 00:03:18,000 --> 00:03:20,000
343
+ The only thing is it will be default.
344
+
345
+ 87
346
+ 00:03:20,000 --> 00:03:22,000
347
+ It will be blank if you don't mention.
348
+
349
+ 88
350
+ 00:03:22,000 --> 00:03:23,000
351
+ But if you want to do something, of course,
352
+
353
+ 89
354
+ 00:03:23,000 --> 00:03:25,000
355
+ you have to mention that explicitly.
356
+
357
+ 90
358
+ 00:03:25,000 --> 00:03:27,000
359
+ And we can use the same code
360
+
361
+ 91
362
+ 00:03:27,000 --> 00:03:31,000
363
+ or I can actually ask my IDE to give me the code.
364
+
365
+ 92
366
+ 00:03:31,000 --> 00:03:34,000
367
+ So, you can simply go to Source and Action
368
+
369
+ 93
370
+ 00:03:34,000 --> 00:03:37,000
371
+ and you can say, hey, I want to create a constructor,
372
+
373
+ 94
374
+ 00:03:37,000 --> 00:03:38,000
375
+ but which constructor?
376
+
377
+ 95
378
+ 00:03:38,000 --> 00:03:41,000
379
+ So, I want a constructor which takes both these arguments.
380
+
381
+ 96
382
+ 00:03:41,000 --> 00:03:44,000
383
+ And I also want a default constructor.
384
+
385
+ 97
386
+ 00:03:44,000 --> 00:03:46,000
387
+ Source Action.
388
+
389
+ 98
390
+ 00:03:46,000 --> 00:03:48,000
391
+ I want a constructor which is default.
392
+
393
+ 99
394
+ 00:03:48,000 --> 00:03:51,000
395
+ You can see we got two constructors.
396
+
397
+ 100
398
+ 00:03:51,000 --> 00:03:52,000
399
+ There's only one change.
400
+
401
+ 101
402
+ 00:03:52,000 --> 00:03:56,000
403
+ The syntax which we have return was a and name,
404
+
405
+ 102
406
+ 00:03:56,000 --> 00:03:58,000
407
+ and here if you can see, we have age and name.
408
+
409
+ 103
410
+ 00:03:58,000 --> 00:04:01,000
411
+ And to make it work, we have to use this keyword.
412
+
413
+ 104
414
+ 00:04:01,000 --> 00:04:03,000
415
+ I hope you remember this keyword video previously.
416
+
417
+ 105
418
+ 00:04:03,000 --> 00:04:06,000
419
+ And that's how it works. It has the same way which works.
420
+
421
+ 106
422
+ 00:04:06,000 --> 00:04:08,000
423
+ The only thing is we have to assign the values here.
424
+
425
+ 107
426
+ 00:04:08,000 --> 00:04:13,000
427
+ I will say age is equal to 12 and the name is John.
428
+
429
+ 108
430
+ 00:04:13,000 --> 00:04:16,000
431
+ So, that's how we can basically use a default constructor
432
+
433
+ 109
434
+ 00:04:16,000 --> 00:04:17,000
435
+ and a parameterized constructor.
436
+
437
+ 110
438
+ 00:04:17,000 --> 00:04:19,000
439
+ Of course, we can create some more constructor here.
440
+
441
+ 111
442
+ 00:04:19,000 --> 00:04:22,000
443
+ What if you want to just specify the name,
444
+
445
+ 112
446
+ 00:04:22,000 --> 00:04:23,000
447
+ not the role number?
448
+
449
+ 113
450
+ 00:04:23,000 --> 00:04:28,000
451
+ So you can say, I want a constructor, Source Action,
452
+
453
+ 114
454
+ 00:04:29,000 --> 00:04:32,000
455
+ and I want a constructor which takes only name.
456
+
457
+ 115
458
+ 00:04:32,000 --> 00:04:33,000
459
+ So you can see we've got a constructor
460
+
461
+ 116
462
+ 00:04:33,000 --> 00:04:34,000
463
+ which only takes a name.
464
+
465
+ 117
466
+ 00:04:34,000 --> 00:04:36,000
467
+ Now what happens to this type of objects?
468
+
469
+ 118
470
+ 00:04:36,000 --> 00:04:38,000
471
+ Example, if I create an object here,
472
+
473
+ 119
474
+ 00:04:38,000 --> 00:04:39,000
475
+ let's say the second object,
476
+
477
+ 120
478
+ 00:04:39,000 --> 00:04:41,000
479
+ and this time I'm not passing two values.
480
+
481
+ 121
482
+ 00:04:41,000 --> 00:04:43,000
483
+ I'm just passing one value, which is name.
484
+
485
+ 122
486
+ 00:04:43,000 --> 00:04:47,000
487
+ In this case, the age will be zero.
488
+
489
+ 123
490
+ 00:04:47,000 --> 00:04:49,000
491
+ So what you can do is even if you're accepting name,
492
+
493
+ 124
494
+ 00:04:49,000 --> 00:04:52,000
495
+ you can assign the age by year, so we can say 12.
496
+
497
+ 125
498
+ 00:04:52,000 --> 00:04:53,000
499
+ You can say age because there's no confusion
500
+
501
+ 126
502
+ 00:04:53,000 --> 00:04:55,000
503
+ or you can also say this.age
504
+
505
+ 127
506
+ 00:04:55,000 --> 00:04:57,000
507
+ just to maintain the uniformity.
508
+
509
+ 128
510
+ 00:04:57,000 --> 00:05:00,000
511
+ Okay, so that's how we use constructors,
512
+
513
+ 129
514
+ 00:05:00,000 --> 00:05:03,000
515
+ default constructors, parameterized constructors,
516
+
517
+ 130
518
+ 00:05:03,000 --> 00:05:04,000
519
+ and yeah, that's it.
520
+
02 - Core Java/048 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/049 Naming Convention_en.srt ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: In this video, let's talk about the naming conventions.
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:08,000
11
+ Now, if you see the code which we are written till now,
12
+
13
+ 4
14
+ 00:00:08,000 --> 00:00:11,000
15
+ somewhere, I was using capital letters,
16
+
17
+ 5
18
+ 00:00:11,000 --> 00:00:13,000
19
+ I was using small letters.
20
+
21
+ 6
22
+ 00:00:13,000 --> 00:00:14,000
23
+ When to use what?
24
+
25
+ 7
26
+ 00:00:14,000 --> 00:00:17,000
27
+ And then what if you want to join two words?
28
+
29
+ 8
30
+ 00:00:17,000 --> 00:00:19,000
31
+ How will you make it more readable?
32
+
33
+ 9
34
+ 00:00:19,000 --> 00:00:21,000
35
+ Now that's where Java says it follows a naming convention
36
+
37
+ 10
38
+ 00:00:21,000 --> 00:00:22,000
39
+ of camel casing.
40
+
41
+ 11
42
+ 00:00:22,000 --> 00:00:26,000
43
+ So basically, it uses camel casing.
44
+
45
+ 12
46
+ 00:00:26,000 --> 00:00:27,000
47
+ Now, what camel casing means,
48
+
49
+ 13
50
+ 00:00:27,000 --> 00:00:30,000
51
+ or let's talk about in general how do we name our classes?
52
+
53
+ 14
54
+ 00:00:30,000 --> 00:00:32,000
55
+ Now, whenever you create a class,
56
+
57
+ 15
58
+ 00:00:32,000 --> 00:00:34,000
59
+ a class name should start with a capital letter.
60
+
61
+ 16
62
+ 00:00:34,000 --> 00:00:36,000
63
+ So when you talk about class,
64
+
65
+ 17
66
+ 00:00:36,000 --> 00:00:37,000
67
+ it should start with a capital letter.
68
+
69
+ 18
70
+ 00:00:37,000 --> 00:00:40,000
71
+ Example, if you want to get a class called Calculator,
72
+
73
+ 19
74
+ 00:00:40,000 --> 00:00:41,000
75
+ the C should be capital.
76
+
77
+ 20
78
+ 00:00:41,000 --> 00:00:44,000
79
+ Now on the other hand, if you talk about variables
80
+
81
+ 21
82
+ 00:00:44,000 --> 00:00:48,000
83
+ or methods, so for variable and methods,
84
+
85
+ 22
86
+ 00:00:48,000 --> 00:00:52,000
87
+ what you will follow is you will start with a small letter.
88
+
89
+ 23
90
+ 00:00:52,000 --> 00:00:54,000
91
+ Example, if your variable name can be marks,
92
+
93
+ 24
94
+ 00:00:54,000 --> 00:00:56,000
95
+ a method name can be show.
96
+
97
+ 25
98
+ 00:00:56,000 --> 00:00:58,000
99
+ So, it will always start with small.
100
+
101
+ 26
102
+ 00:00:58,000 --> 00:01:02,000
103
+ Class, capital, variable, method, small.
104
+
105
+ 27
106
+ 00:01:02,000 --> 00:01:04,000
107
+ In fact, we also have a concept of interfaces,
108
+
109
+ 28
110
+ 00:01:04,000 --> 00:01:05,000
111
+ which we'll discuss later.
112
+
113
+ 29
114
+ 00:01:05,000 --> 00:01:08,000
115
+ So if we talk about classes and interface,
116
+
117
+ 30
118
+ 00:01:08,000 --> 00:01:10,000
119
+ we'll have to make it capital.
120
+
121
+ 31
122
+ 00:01:10,000 --> 00:01:12,000
123
+ Let's say interface is Runable.
124
+
125
+ 32
126
+ 00:01:12,000 --> 00:01:14,000
127
+ So basically, this is the convention which we follow.
128
+
129
+ 33
130
+ 00:01:14,000 --> 00:01:17,000
131
+ Class, interface, we have capital letters,
132
+
133
+ 34
134
+ 00:01:17,000 --> 00:01:19,000
135
+ variable, methods, we have small letters.
136
+
137
+ 35
138
+ 00:01:19,000 --> 00:01:21,000
139
+ We also have a concept of constants,
140
+
141
+ 36
142
+ 00:01:21,000 --> 00:01:23,000
143
+ which we have talked about.
144
+
145
+ 37
146
+ 00:01:23,000 --> 00:01:27,000
147
+ So when you talk about constants, it will have a capital,
148
+
149
+ 38
150
+ 00:01:27,000 --> 00:01:28,000
151
+ but all capital.
152
+
153
+ 39
154
+ 00:01:28,000 --> 00:01:30,000
155
+ Example, if we talk about the value of PIE,
156
+
157
+ 40
158
+ 00:01:30,000 --> 00:01:34,000
159
+ if we talk about a constant of BRAND,
160
+
161
+ 41
162
+ 00:01:34,000 --> 00:01:35,000
163
+ so doesn't matter what your constant is.
164
+
165
+ 42
166
+ 00:01:35,000 --> 00:01:39,000
167
+ So you can have all capital here. Now, why do we do this?
168
+
169
+ 43
170
+ 00:01:39,000 --> 00:01:41,000
171
+ We do this just to see and understand
172
+
173
+ 44
174
+ 00:01:41,000 --> 00:01:43,000
175
+ what could be the thing which you are doing.
176
+
177
+ 45
178
+ 00:01:43,000 --> 00:01:46,000
179
+ Example, if you say, if you see this type of things,
180
+
181
+ 46
182
+ 00:01:46,000 --> 00:01:49,000
183
+ you can guess, hey, it can be a class or interface.
184
+
185
+ 47
186
+ 00:01:49,000 --> 00:01:52,000
187
+ If you look at this, you know this is a variable.
188
+
189
+ 48
190
+ 00:01:52,000 --> 00:01:54,000
191
+ If you look at this, you know this is a method.
192
+
193
+ 49
194
+ 00:01:54,000 --> 00:01:57,000
195
+ And when you look at this, you know these are constants.
196
+
197
+ 50
198
+ 00:01:57,000 --> 00:01:59,000
199
+ It makes your code much more readable.
200
+
201
+ 51
202
+ 00:01:59,000 --> 00:02:00,000
203
+ And that's important, right?
204
+
205
+ 52
206
+ 00:02:00,000 --> 00:02:03,000
207
+ It's very easy to write a code which works.
208
+
209
+ 53
210
+ 00:02:03,000 --> 00:02:05,000
211
+ It's difficult to write a code which anyone can read,
212
+
213
+ 54
214
+ 00:02:05,000 --> 00:02:08,000
215
+ and that's why you should follow this convention.
216
+
217
+ 55
218
+ 00:02:08,000 --> 00:02:11,000
219
+ So, this is how you use the main convention.
220
+
221
+ 56
222
+ 00:02:11,000 --> 00:02:14,000
223
+ But what if you have a word which which has two letters?
224
+
225
+ 57
226
+ 00:02:14,000 --> 00:02:17,000
227
+ Example, if you talk about, show my marks.
228
+
229
+ 58
230
+ 00:02:17,000 --> 00:02:21,000
231
+ If I want to do this, so you have to say, showMyMarks,
232
+
233
+ 59
234
+ 00:02:21,000 --> 00:02:24,000
235
+ because if you say showmymarks,
236
+
237
+ 60
238
+ 00:02:24,000 --> 00:02:27,000
239
+ it is actually a bit difficult to read, right?
240
+
241
+ 61
242
+ 00:02:27,000 --> 00:02:30,000
243
+ So what you can do is every time you combine words,
244
+
245
+ 62
246
+ 00:02:30,000 --> 00:02:31,000
247
+ make sure that the first letter of the second word
248
+
249
+ 63
250
+ 00:02:31,000 --> 00:02:34,000
251
+ or the first letter make it capital.
252
+
253
+ 64
254
+ 00:02:34,000 --> 00:02:37,000
255
+ It makes it much more readable compared to small letters.
256
+
257
+ 65
258
+ 00:02:37,000 --> 00:02:39,000
259
+ Now, this is what camel casing means.
260
+
261
+ 66
262
+ 00:02:39,000 --> 00:02:41,000
263
+ You know we have camel, so it goes up and down.
264
+
265
+ 67
266
+ 00:02:41,000 --> 00:02:45,000
267
+ So we have small letters, then we have in between,
268
+
269
+ 68
270
+ 00:02:45,000 --> 00:02:47,000
271
+ we have capital, small, again, we have capital.
272
+
273
+ 69
274
+ 00:02:47,000 --> 00:02:49,000
275
+ So this is camel casing.
276
+
277
+ 70
278
+ 00:02:49,000 --> 00:02:51,000
279
+ Now, apart from this, there are different languages
280
+
281
+ 71
282
+ 00:02:51,000 --> 00:02:53,000
283
+ which follow snake casing rule
284
+
285
+ 72
286
+ 00:02:53,000 --> 00:02:54,000
287
+ where we use underscores.
288
+
289
+ 73
290
+ 00:02:54,000 --> 00:02:58,000
291
+ Example, in some languages, they follow snake casing.
292
+
293
+ 74
294
+ 00:02:58,000 --> 00:02:59,000
295
+ They use underscore.
296
+
297
+ 75
298
+ 00:02:59,000 --> 00:03:01,000
299
+ And people who jump between different languages,
300
+
301
+ 76
302
+ 00:03:01,000 --> 00:03:04,000
303
+ they get this tendency of using underscore.
304
+
305
+ 77
306
+ 00:03:04,000 --> 00:03:06,000
307
+ So, again, Java will not give you any error,
308
+
309
+ 78
310
+ 00:03:06,000 --> 00:03:08,000
311
+ but if you follow the Java pattern,
312
+
313
+ 79
314
+ 00:03:08,000 --> 00:03:10,000
315
+ Java developers will not like this.
316
+
317
+ 80
318
+ 00:03:10,000 --> 00:03:12,000
319
+ So, if you're writing a code where you have a Java team
320
+
321
+ 81
322
+ 00:03:12,000 --> 00:03:15,000
323
+ or everyone who works on Java, try to follow camel casing
324
+
325
+ 82
326
+ 00:03:15,000 --> 00:03:18,000
327
+ and, but again, it will not give you error.
328
+
329
+ 83
330
+ 00:03:18,000 --> 00:03:19,000
331
+ It perfectly works.
332
+
333
+ 84
334
+ 00:03:19,000 --> 00:03:22,000
335
+ Underscore works in the names, but that's what we follow.
336
+
337
+ 85
338
+ 00:03:22,000 --> 00:03:26,000
339
+ We follow camel casing here, not snake casing, yeah?
340
+
341
+ 86
342
+ 00:03:26,000 --> 00:03:29,000
343
+ If you have the class name, which is again,
344
+
345
+ 87
346
+ 00:03:29,000 --> 00:03:32,000
347
+ I want to say MyData is a class,
348
+
349
+ 88
350
+ 00:03:32,000 --> 00:03:36,000
351
+ so you can say M is capital because that's a class name.
352
+
353
+ 89
354
+ 00:03:36,000 --> 00:03:38,000
355
+ Now I will give you, I will show you some names
356
+
357
+ 90
358
+ 00:03:38,000 --> 00:03:40,000
359
+ and you have to guess what those are.
360
+
361
+ 91
362
+ 00:03:40,000 --> 00:03:44,000
363
+ Example, if I say age, that's variable, right, okay?
364
+
365
+ 92
366
+ 00:03:44,000 --> 00:03:47,000
367
+ What if I say DATA? What is this?
368
+
369
+ 93
370
+ 00:03:47,000 --> 00:03:51,000
371
+ This is a constant because everything is capital, okay?
372
+
373
+ 94
374
+ 00:03:51,000 --> 00:03:54,000
375
+ Yeah, in terms of constant, if you want to say my data,
376
+
377
+ 95
378
+ 00:03:54,000 --> 00:03:56,000
379
+ which is a constant, you have to use MYDATA,
380
+
381
+ 96
382
+ 00:03:56,000 --> 00:03:58,000
383
+ but again, everything is capital, right?
384
+
385
+ 97
386
+ 00:03:58,000 --> 00:03:59,000
387
+ So at this point, you can use underscore
388
+
389
+ 98
390
+ 00:03:59,000 --> 00:04:02,000
391
+ just to differentiate this, and again,
392
+
393
+ 99
394
+ 00:04:02,000 --> 00:04:03,000
395
+ these are the good practices which I'm showing you.
396
+
397
+ 100
398
+ 00:04:03,000 --> 00:04:04,000
399
+ How about this?
400
+
401
+ 101
402
+ 00:04:04,000 --> 00:04:08,000
403
+ If I use something like Human, but I use a round bracket.
404
+
405
+ 102
406
+ 00:04:08,000 --> 00:04:10,000
407
+ Any guess? Yeah, that's a constructor.
408
+
409
+ 103
410
+ 00:04:10,000 --> 00:04:11,000
411
+ Why is a constructor?
412
+
413
+ 104
414
+ 00:04:11,000 --> 00:04:14,000
415
+ Is because the first letter is capital.
416
+
417
+ 105
418
+ 00:04:14,000 --> 00:04:16,000
419
+ That means it represents a class name.
420
+
421
+ 106
422
+ 00:04:16,000 --> 00:04:17,000
423
+ And we also have a round bracket,
424
+
425
+ 107
426
+ 00:04:17,000 --> 00:04:20,000
427
+ method like something, so that's a constructor.
428
+
429
+ 108
430
+ 00:04:20,000 --> 00:04:22,000
431
+ So this is a naming convention which we follow
432
+
433
+ 109
434
+ 00:04:22,000 --> 00:04:25,000
435
+ and try to use good names for your variables, your classes,
436
+
437
+ 110
438
+ 00:04:25,000 --> 00:04:29,000
439
+ your methods, so that it will be easy for others to read.
440
+
02 - Core Java/049 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/050 Anonymous Object_en.srt ADDED
@@ -0,0 +1,508 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: Okay, so now we know how to create the object, right?
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:06,000
11
+ So we have a class.
12
+
13
+ 4
14
+ 00:00:06,000 --> 00:00:08,000
15
+ Let's say we have a class A,
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:10,000
19
+ and then in this class A, we have a show method.
20
+
21
+ 6
22
+ 00:00:10,000 --> 00:00:11,000
23
+ Now, how do we call show method?
24
+
25
+ 7
26
+ 00:00:11,000 --> 00:00:12,000
27
+ That's very simple.
28
+
29
+ 8
30
+ 00:00:12,000 --> 00:00:14,000
31
+ First you have to create the object of A,
32
+
33
+ 9
34
+ 00:00:14,000 --> 00:00:16,000
35
+ and then you can call the show method.
36
+
37
+ 10
38
+ 00:00:16,000 --> 00:00:17,000
39
+ Now what happens behind the scenes?
40
+
41
+ 11
42
+ 00:00:17,000 --> 00:00:21,000
43
+ So of course you have your big JVM here,
44
+
45
+ 12
46
+ 00:00:21,000 --> 00:00:24,000
47
+ and then in this you'll be having your stack memory
48
+
49
+ 13
50
+ 00:00:24,000 --> 00:00:26,000
51
+ and then you'll be having your heap memory as well.
52
+
53
+ 14
54
+ 00:00:26,000 --> 00:00:29,000
55
+ Now, in this heap memory, so if you look at line number 14,
56
+
57
+ 15
58
+ 00:00:29,000 --> 00:00:31,000
59
+ it will create an object.
60
+
61
+ 16
62
+ 00:00:31,000 --> 00:00:33,000
63
+ Let's say the address is 1 0 1,
64
+
65
+ 17
66
+ 00:00:33,000 --> 00:00:36,000
67
+ and then in this you'll be having a variable or methods.
68
+
69
+ 18
70
+ 00:00:36,000 --> 00:00:37,000
71
+ We don't have a variable as of now.
72
+
73
+ 19
74
+ 00:00:37,000 --> 00:00:39,000
75
+ So let's say we have a method which is show.
76
+
77
+ 20
78
+ 00:00:39,000 --> 00:00:41,000
79
+ So of course in order to call this show, we need objects.
80
+
81
+ 21
82
+ 00:00:41,000 --> 00:00:44,000
83
+ So we have done that, and then we have OBJ here.
84
+
85
+ 22
86
+ 00:00:44,000 --> 00:00:48,000
87
+ The address will be 1 0 1 and it will refer here.
88
+
89
+ 23
90
+ 00:00:48,000 --> 00:00:50,000
91
+ And then every time you want to call show,
92
+
93
+ 24
94
+ 00:00:50,000 --> 00:00:54,000
95
+ basically you have to say obj.show.
96
+
97
+ 25
98
+ 00:00:54,000 --> 00:00:56,000
99
+ That's how it works, right? Okay.
100
+
101
+ 26
102
+ 00:00:56,000 --> 00:00:58,000
103
+ Now just to clear the things,
104
+
105
+ 27
106
+ 00:00:58,000 --> 00:01:01,000
107
+ this OBJ here is not called the object.
108
+
109
+ 28
110
+ 00:01:01,000 --> 00:01:04,000
111
+ It is called a reference variable, right?
112
+
113
+ 29
114
+ 00:01:04,000 --> 00:01:07,000
115
+ So this is your reference variable.
116
+
117
+ 30
118
+ 00:01:07,000 --> 00:01:08,000
119
+ Why this called a reference variable?
120
+
121
+ 31
122
+ 00:01:08,000 --> 00:01:09,000
123
+ Because it's referring to an object.
124
+
125
+ 32
126
+ 00:01:09,000 --> 00:01:10,000
127
+ The object is here.
128
+
129
+ 33
130
+ 00:01:10,000 --> 00:01:13,000
131
+ So this is your object, okay?
132
+
133
+ 34
134
+ 00:01:13,000 --> 00:01:15,000
135
+ So the question is, if I want to create this object,
136
+
137
+ 35
138
+ 00:01:15,000 --> 00:01:18,000
139
+ is this line compulsory or do we have a shortcut?
140
+
141
+ 36
142
+ 00:01:18,000 --> 00:01:19,000
143
+ Now to understand this mode,
144
+
145
+ 37
146
+ 00:01:19,000 --> 00:01:21,000
147
+ let's also use a concept of constructor.
148
+
149
+ 38
150
+ 00:01:21,000 --> 00:01:23,000
151
+ So let's say we have a constructor here, which is A,
152
+
153
+ 39
154
+ 00:01:23,000 --> 00:01:26,000
155
+ and then I'm just trying to print something here,
156
+
157
+ 40
158
+ 00:01:26,000 --> 00:01:28,000
159
+ it says object created.
160
+
161
+ 41
162
+ 00:01:28,000 --> 00:01:30,000
163
+ So of course we know every time you create the object,
164
+
165
+ 42
166
+ 00:01:30,000 --> 00:01:33,000
167
+ it will call the constructor as well.
168
+
169
+ 43
170
+ 00:01:33,000 --> 00:01:33,000
171
+ So it should print.
172
+
173
+ 44
174
+ 00:01:33,000 --> 00:01:36,000
175
+ So if I compile and run this code,
176
+
177
+ 45
178
+ 00:01:36,000 --> 00:01:38,000
179
+ you can see it says object created
180
+
181
+ 46
182
+ 00:01:38,000 --> 00:01:40,000
183
+ and it is printing in a show.
184
+
185
+ 47
186
+ 00:01:40,000 --> 00:01:42,000
187
+ Now, actually, if you look at this line here,
188
+
189
+ 48
190
+ 00:01:42,000 --> 00:01:44,000
191
+ there are two steps, not one.
192
+
193
+ 49
194
+ 00:01:44,000 --> 00:01:46,000
195
+ Example, so let's say if you create
196
+
197
+ 50
198
+ 00:01:46,000 --> 00:01:49,000
199
+ a local variable called marks, okay?
200
+
201
+ 51
202
+ 00:01:49,000 --> 00:01:51,000
203
+ And then you set the marks for it,
204
+
205
+ 52
206
+ 00:01:51,000 --> 00:01:52,000
207
+ you set the value for it.
208
+
209
+ 53
210
+ 00:01:52,000 --> 00:01:54,000
211
+ Let's say 99,
212
+
213
+ 54
214
+ 00:01:54,000 --> 00:01:56,000
215
+ we hate, everyone hates this type of people, right?
216
+
217
+ 55
218
+ 00:01:56,000 --> 00:01:58,000
219
+ Anyway, so we have this variable.
220
+
221
+ 56
222
+ 00:01:58,000 --> 00:02:00,000
223
+ So what we are doing is we are first of all
224
+
225
+ 57
226
+ 00:02:00,000 --> 00:02:04,000
227
+ declaring the variable and then we are as assigning a value.
228
+
229
+ 58
230
+ 00:02:04,000 --> 00:02:06,000
231
+ The same thing can be done for this thing, right?
232
+
233
+ 59
234
+ 00:02:06,000 --> 00:02:08,000
235
+ We can do it in two steps.
236
+
237
+ 60
238
+ 00:02:08,000 --> 00:02:09,000
239
+ We can declare the object
240
+
241
+ 61
242
+ 00:02:09,000 --> 00:02:13,000
243
+ and then we can say OBJ equal to new A.
244
+
245
+ 62
246
+ 00:02:13,000 --> 00:02:15,000
247
+ Now this is called reference creation, right?
248
+
249
+ 63
250
+ 00:02:15,000 --> 00:02:17,000
251
+ This is where you're creating a reference and then
252
+
253
+ 64
254
+ 00:02:17,000 --> 00:02:19,000
255
+ this is where you are creating an object
256
+
257
+ 65
258
+ 00:02:19,000 --> 00:02:23,000
259
+ and assigning the value to OBJ.
260
+
261
+ 66
262
+ 00:02:23,000 --> 00:02:26,000
263
+ That means this is, I mean, when you say new A,
264
+
265
+ 67
266
+ 00:02:26,000 --> 00:02:29,000
267
+ this is where you create the object.
268
+
269
+ 68
270
+ 00:02:29,000 --> 00:02:30,000
271
+ Let me show that.
272
+
273
+ 69
274
+ 00:02:30,000 --> 00:02:35,000
275
+ Let me remove everything from here and say new A,
276
+
277
+ 70
278
+ 00:02:35,000 --> 00:02:38,000
279
+ this is object creation, not the entire line.
280
+
281
+ 71
282
+ 00:02:38,000 --> 00:02:41,000
283
+ When you say new A constructor,
284
+
285
+ 72
286
+ 00:02:41,000 --> 00:02:43,000
287
+ that is your object creation.
288
+
289
+ 73
290
+ 00:02:43,000 --> 00:02:45,000
291
+ The moment you do that in your heap memory,
292
+
293
+ 74
294
+ 00:02:45,000 --> 00:02:48,000
295
+ of course we don't have all this data now,
296
+
297
+ 75
298
+ 00:02:48,000 --> 00:02:50,000
299
+ so ignore all this data, which is there,
300
+
301
+ 76
302
+ 00:02:50,000 --> 00:02:52,000
303
+ let me just remove this. This is not there.
304
+
305
+ 77
306
+ 00:02:52,000 --> 00:02:53,000
307
+ Imagine there's no object.
308
+
309
+ 78
310
+ 00:02:53,000 --> 00:02:55,000
311
+ So this line will create an object,
312
+
313
+ 79
314
+ 00:02:55,000 --> 00:02:58,000
315
+ doesn't matter what's the address. Let's say 5 0 1,
316
+
317
+ 80
318
+ 00:02:58,000 --> 00:03:01,000
319
+ and it will have this show method, okay?
320
+
321
+ 81
322
+ 00:03:01,000 --> 00:03:04,000
323
+ The only thing is we are not doing anything.
324
+
325
+ 82
326
+ 00:03:04,000 --> 00:03:06,000
327
+ We are not creating any variable inside stack.
328
+
329
+ 83
330
+ 00:03:06,000 --> 00:03:10,000
331
+ Example, when you say int marks, the moment you do that,
332
+
333
+ 84
334
+ 00:03:10,000 --> 00:03:13,000
335
+ it will create a int variable called marks, here.
336
+
337
+ 85
338
+ 00:03:13,000 --> 00:03:15,000
339
+ The value will be blank.
340
+
341
+ 86
342
+ 00:03:15,000 --> 00:03:17,000
343
+ And whatever value you want to assign,
344
+
345
+ 87
346
+ 00:03:17,000 --> 00:03:18,000
347
+ you can assign that here.
348
+
349
+ 88
350
+ 00:03:18,000 --> 00:03:20,000
351
+ But if you can see, we are not doing anything here.
352
+
353
+ 89
354
+ 00:03:20,000 --> 00:03:22,000
355
+ We are just creating a object,
356
+
357
+ 90
358
+ 00:03:22,000 --> 00:03:26,000
359
+ that is created inside the heap memory, nothing in stack.
360
+
361
+ 91
362
+ 00:03:26,000 --> 00:03:29,000
363
+ And if you don't trust me, let me just show you the proof.
364
+
365
+ 92
366
+ 00:03:29,000 --> 00:03:34,000
367
+ If I compile this code and run, it says object created.
368
+
369
+ 93
370
+ 00:03:34,000 --> 00:03:36,000
371
+ This is the object,
372
+
373
+ 94
374
+ 00:03:36,000 --> 00:03:40,000
375
+ and this type of objects are called anonymous object.
376
+
377
+ 95
378
+ 00:03:40,000 --> 00:03:40,000
379
+ You know why?
380
+
381
+ 96
382
+ 00:03:40,000 --> 00:03:43,000
383
+ It's because this type of object don't have a name, right?
384
+
385
+ 97
386
+ 00:03:43,000 --> 00:03:45,000
387
+ What do you call when you have a reference?
388
+
389
+ 98
390
+ 00:03:45,000 --> 00:03:47,000
391
+ It is called a referenced object.
392
+
393
+ 99
394
+ 00:03:47,000 --> 00:03:49,000
395
+ Okay, because there's a reference in this stack.
396
+
397
+ 100
398
+ 00:03:49,000 --> 00:03:51,000
399
+ So when you say OBJ, there's a reference here.
400
+
401
+ 101
402
+ 00:03:51,000 --> 00:03:54,000
403
+ For the anonymous object, there is no reference.
404
+
405
+ 102
406
+ 00:03:54,000 --> 00:03:56,000
407
+ The only problem with this type of object is
408
+
409
+ 103
410
+ 00:03:56,000 --> 00:03:58,000
411
+ you can't reuse them. Once you have written this line,
412
+
413
+ 104
414
+ 00:03:58,000 --> 00:04:02,000
415
+ you got the new object in the heap, how will you use it?
416
+
417
+ 105
418
+ 00:04:02,000 --> 00:04:03,000
419
+ That's the problem, right?
420
+
421
+ 106
422
+ 00:04:03,000 --> 00:04:04,000
423
+ So you should use this type of object
424
+
425
+ 107
426
+ 00:04:04,000 --> 00:04:05,000
427
+ only when it's required.
428
+
429
+ 108
430
+ 00:04:05,000 --> 00:04:08,000
431
+ So let's say if you want to call show,
432
+
433
+ 109
434
+ 00:04:08,000 --> 00:04:09,000
435
+ you can actually call this, okay?
436
+
437
+ 110
438
+ 00:04:09,000 --> 00:04:12,000
439
+ So you can say new A,
440
+
441
+ 111
442
+ 00:04:12,000 --> 00:04:13,000
443
+ dot show.
444
+
445
+ 112
446
+ 00:04:13,000 --> 00:04:15,000
447
+ This is object, right? This is object.
448
+
449
+ 113
450
+ 00:04:15,000 --> 00:04:17,000
451
+ So using the object you can call show.
452
+
453
+ 114
454
+ 00:04:17,000 --> 00:04:21,000
455
+ The only thing is you can't use the same object again.
456
+
457
+ 115
458
+ 00:04:21,000 --> 00:04:24,000
459
+ So if I compile and run, it worked.
460
+
461
+ 116
462
+ 00:04:24,000 --> 00:04:28,000
463
+ The only thing is you can't use this object once more.
464
+
465
+ 117
466
+ 00:04:28,000 --> 00:04:30,000
467
+ So if you write this line once more, what will happen?
468
+
469
+ 118
470
+ 00:04:30,000 --> 00:04:33,000
471
+ Now, I mentioned that you can't reuse it.
472
+
473
+ 119
474
+ 00:04:33,000 --> 00:04:34,000
475
+ What happens when you do that?
476
+
477
+ 120
478
+ 00:04:34,000 --> 00:04:36,000
479
+ You can see it says object created.
480
+
481
+ 121
482
+ 00:04:36,000 --> 00:04:38,000
483
+ So it has created two objects.
484
+
485
+ 122
486
+ 00:04:38,000 --> 00:04:43,000
487
+ Every time you say new A, it creates a new object.
488
+
489
+ 123
490
+ 00:04:43,000 --> 00:04:45,000
491
+ So wherever you want to use a normal object,
492
+
493
+ 124
494
+ 00:04:45,000 --> 00:04:47,000
495
+ you can use this other objects.
496
+
497
+ 125
498
+ 00:04:47,000 --> 00:04:48,000
499
+ Okay, so that's it.
500
+
501
+ 126
502
+ 00:04:48,000 --> 00:04:49,000
503
+ That's it from this video
504
+
505
+ 127
506
+ 00:04:49,000 --> 00:04:51,000
507
+ where we talked about anonymous objects.
508
+
02 - Core Java/050 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/051 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/051 What is Inheritance_en.srt ADDED
@@ -0,0 +1,848 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:02,000
3
+ (gentle music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:04,000
7
+ -: So in theory, we have talked
8
+
9
+ 3
10
+ 00:00:04,000 --> 00:00:06,000
11
+ about what is inheritance, right?
12
+
13
+ 4
14
+ 00:00:06,000 --> 00:00:09,000
15
+ Basically, you can just use the features of a superclass.
16
+
17
+ 5
18
+ 00:00:09,000 --> 00:00:12,000
19
+ Let's try to implement that in this code.
20
+
21
+ 6
22
+ 00:00:12,000 --> 00:00:13,000
23
+ Of course, we'll not be working with Humans anymore.
24
+
25
+ 7
26
+ 00:00:13,000 --> 00:00:18,000
27
+ Let me just remove the entire code from here, and all gone.
28
+
29
+ 8
30
+ 00:00:18,000 --> 00:00:22,000
31
+ And let me also make sure that this is empty, gone.
32
+
33
+ 9
34
+ 00:00:22,000 --> 00:00:24,000
35
+ So we have a very simple method, which is main here.
36
+
37
+ 10
38
+ 00:00:24,000 --> 00:00:26,000
39
+ Now what I wanna do is I want
40
+
41
+ 11
42
+ 00:00:26,000 --> 00:00:28,000
43
+ to take the same example of calculator here.
44
+
45
+ 12
46
+ 00:00:28,000 --> 00:00:30,000
47
+ So let me get a class called Calc,
48
+
49
+ 13
50
+ 00:00:30,000 --> 00:00:32,000
51
+ and of course, I can just create this thing
52
+
53
+ 14
54
+ 00:00:32,000 --> 00:00:35,000
55
+ in some other files as well, that actually makes sense.
56
+
57
+ 15
58
+ 00:00:35,000 --> 00:00:39,000
59
+ But just to keep it simple, I'm using the same file here.
60
+
61
+ 16
62
+ 00:00:39,000 --> 00:00:41,000
63
+ So we got a class called calculator,
64
+
65
+ 17
66
+ 00:00:41,000 --> 00:00:43,000
67
+ and in this, I can add some methods and some variables.
68
+
69
+ 18
70
+ 00:00:43,000 --> 00:00:46,000
71
+ So let's say I will define some methods here,
72
+
73
+ 19
74
+ 00:00:46,000 --> 00:00:49,000
75
+ and I'll say public int, it can add two numbers.
76
+
77
+ 20
78
+ 00:00:49,000 --> 00:00:53,000
79
+ It will accept two integers as well, I would say n1, n2.
80
+
81
+ 21
82
+ 00:00:53,000 --> 00:00:55,000
83
+ So we got two variables, right?
84
+
85
+ 22
86
+ 00:00:55,000 --> 00:01:00,000
87
+ And then I can just return n1 + n2, okay?
88
+
89
+ 23
90
+ 00:01:00,000 --> 00:01:03,000
91
+ Now let's say in this calculator, we have two methods.
92
+
93
+ 24
94
+ 00:01:03,000 --> 00:01:08,000
95
+ One is add and one is sub, which is sub here.
96
+
97
+ 25
98
+ 00:01:08,000 --> 00:01:09,000
99
+ And there will be a subtraction operation.
100
+
101
+ 26
102
+ 00:01:09,000 --> 00:01:11,000
103
+ So we got two methods, right?
104
+
105
+ 27
106
+ 00:01:11,000 --> 00:01:14,000
107
+ Now one thing to remember, if you look at our File Explorer,
108
+
109
+ 28
110
+ 00:01:14,000 --> 00:01:17,000
111
+ every time you get a file, it also creates a class file.
112
+
113
+ 29
114
+ 00:01:17,000 --> 00:01:20,000
115
+ So for every class in your code, it will have a class files.
116
+
117
+ 30
118
+ 00:01:20,000 --> 00:01:24,000
119
+ We have used a Calculator, a Computer,
120
+
121
+ 31
122
+ 00:01:24,000 --> 00:01:25,000
123
+ Human, Student before,
124
+
125
+ 32
126
+ 00:01:25,000 --> 00:01:27,000
127
+ and that's why we have all these classes.
128
+
129
+ 33
130
+ 00:01:27,000 --> 00:01:29,000
131
+ What I will do is I will just delete them.
132
+
133
+ 34
134
+ 00:01:29,000 --> 00:01:31,000
135
+ Okay, so you can see all these classes are gone.
136
+
137
+ 35
138
+ 00:01:31,000 --> 00:01:33,000
139
+ In fact, let me also delete the Demo one
140
+
141
+ 36
142
+ 00:01:33,000 --> 00:01:34,000
143
+ to see what happens.
144
+
145
+ 37
146
+ 00:01:34,000 --> 00:01:36,000
147
+ And that's fine, you can also delete,
148
+
149
+ 38
150
+ 00:01:36,000 --> 00:01:37,000
151
+ you can delete all the class files.
152
+
153
+ 39
154
+ 00:01:37,000 --> 00:01:39,000
155
+ So every time you compile the code,
156
+
157
+ 40
158
+ 00:01:39,000 --> 00:01:40,000
159
+ it will also create a class files for you.
160
+
161
+ 41
162
+ 00:01:40,000 --> 00:01:42,000
163
+ Let me show you that.
164
+
165
+ 42
166
+ 00:01:42,000 --> 00:01:45,000
167
+ So I will say javac, and if I mention the file name,
168
+
169
+ 43
170
+ 00:01:45,000 --> 00:01:49,000
171
+ which is Demo.java, the moment I say Enter,
172
+
173
+ 44
174
+ 00:01:49,000 --> 00:01:50,000
175
+ it will create two class files
176
+
177
+ 45
178
+ 00:01:50,000 --> 00:01:51,000
179
+ because we have two classes.
180
+
181
+ 46
182
+ 00:01:51,000 --> 00:01:55,000
183
+ If I go to Explorer, you can see we got Demo.class,
184
+
185
+ 47
186
+ 00:01:55,000 --> 00:01:57,000
187
+ and we also have Calc.class.
188
+
189
+ 48
190
+ 00:01:57,000 --> 00:01:59,000
191
+ Now when you run this code, if you say java,
192
+
193
+ 49
194
+ 00:01:59,000 --> 00:02:02,000
195
+ and if you say Demo, it will just run the class files.
196
+
197
+ 50
198
+ 00:02:02,000 --> 00:02:04,000
199
+ And as you can see,
200
+
201
+ 51
202
+ 00:02:04,000 --> 00:02:07,000
203
+ we don't have any code here for calculator.
204
+
205
+ 52
206
+ 00:02:07,000 --> 00:02:11,000
207
+ It will only run the Demo class, and that's how it works.
208
+
209
+ 53
210
+ 00:02:11,000 --> 00:02:14,000
211
+ So if I just try to write this code here,
212
+
213
+ 54
214
+ 00:02:14,000 --> 00:02:18,000
215
+ which we already have, and if I try to create object of it,
216
+
217
+ 55
218
+ 00:02:18,000 --> 00:02:19,000
219
+ let's try creating object of it.
220
+
221
+ 56
222
+ 00:02:19,000 --> 00:02:22,000
223
+ In fact, let me do one more thing before we start.
224
+
225
+ 57
226
+ 00:02:22,000 --> 00:02:25,000
227
+ For this example, let me cut this part,
228
+
229
+ 58
230
+ 00:02:25,000 --> 00:02:30,000
231
+ and create a new file and let me say this is Calc.java.
232
+
233
+ 59
234
+ 00:02:31,000 --> 00:02:35,000
235
+ And yes, we have this code here.
236
+
237
+ 60
238
+ 00:02:35,000 --> 00:02:37,000
239
+ So you can see now we have two files, and before I continue,
240
+
241
+ 61
242
+ 00:02:37,000 --> 00:02:40,000
243
+ I will just delete these class files again.
244
+
245
+ 62
246
+ 00:02:40,000 --> 00:02:41,000
247
+ Okay, class file deleted.
248
+
249
+ 63
250
+ 00:02:41,000 --> 00:02:45,000
251
+ And now let me just compile this code once again.
252
+
253
+ 64
254
+ 00:02:45,000 --> 00:02:47,000
255
+ So if you can see when I'm compiling it,
256
+
257
+ 65
258
+ 00:02:47,000 --> 00:02:50,000
259
+ it is only compiling the Demo file.
260
+
261
+ 66
262
+ 00:02:50,000 --> 00:02:53,000
263
+ It is not combining the class.java, right?
264
+
265
+ 67
266
+ 00:02:53,000 --> 00:02:55,000
267
+ But when I create an object of it,
268
+
269
+ 68
270
+ 00:02:55,000 --> 00:02:58,000
271
+ if I create object of Calc obj = new Calc,
272
+
273
+ 69
274
+ 00:02:58,000 --> 00:03:00,000
275
+ of course if you want to use it,
276
+
277
+ 70
278
+ 00:03:00,000 --> 00:03:02,000
279
+ we have to create object first.
280
+
281
+ 71
282
+ 00:03:02,000 --> 00:03:04,000
283
+ And now if I recompile this,
284
+
285
+ 72
286
+ 00:03:04,000 --> 00:03:06,000
287
+ and let's look at the class files.
288
+
289
+ 73
290
+ 00:03:06,000 --> 00:03:08,000
291
+ We got the class file for class as well.
292
+
293
+ 74
294
+ 00:03:08,000 --> 00:03:12,000
295
+ So if you are not using Calc, it will not compile it.
296
+
297
+ 75
298
+ 00:03:12,000 --> 00:03:13,000
299
+ It'll just say, "Hey,
300
+
301
+ 76
302
+ 00:03:13,000 --> 00:03:15,000
303
+ my responsibility is to compile the Java file.
304
+
305
+ 77
306
+ 00:03:15,000 --> 00:03:16,000
307
+ I'm doing it."
308
+
309
+ 78
310
+ 00:03:16,000 --> 00:03:18,000
311
+ But if you want to work with the class,
312
+
313
+ 79
314
+ 00:03:18,000 --> 00:03:21,000
315
+ the Calc.class as well, or Calc.java as well,
316
+
317
+ 80
318
+ 00:03:21,000 --> 00:03:25,000
319
+ you have to create object and that's how it compiles.
320
+
321
+ 81
322
+ 00:03:25,000 --> 00:03:26,000
323
+ Now once the compile is done,
324
+
325
+ 82
326
+ 00:03:26,000 --> 00:03:30,000
327
+ you can simply save the value in r1 or you can say obj.add.
328
+
329
+ 83
330
+ 00:03:30,000 --> 00:03:33,000
331
+ It will add two numbers, let's say four and five.
332
+
333
+ 84
334
+ 00:03:33,000 --> 00:03:35,000
335
+ And then we can also find r2,
336
+
337
+ 85
338
+ 00:03:35,000 --> 00:03:37,000
339
+ which will be result of subtraction.
340
+
341
+ 86
342
+ 00:03:37,000 --> 00:03:41,000
343
+ So I can say sub, I will say seven and three, okay?
344
+
345
+ 87
346
+ 00:03:41,000 --> 00:03:43,000
347
+ So we basically, you can see we got these two methods,
348
+
349
+ 88
350
+ 00:03:43,000 --> 00:03:45,000
351
+ and when you try to print the values,
352
+
353
+ 89
354
+ 00:03:45,000 --> 00:03:48,000
355
+ I will print r1 and I will give us space,
356
+
357
+ 90
358
+ 00:03:48,000 --> 00:03:49,000
359
+ and I'll also print r2.
360
+
361
+ 91
362
+ 00:03:49,000 --> 00:03:51,000
363
+ So basically, I'm just printing two values back to back.
364
+
365
+ 92
366
+ 00:03:51,000 --> 00:03:55,000
367
+ And if I say compile again because we have made some changes
368
+
369
+ 93
370
+ 00:03:55,000 --> 00:03:57,000
371
+ and run, you can see we got nine and four.
372
+
373
+ 94
374
+ 00:03:57,000 --> 00:04:00,000
375
+ So 4 + 5 is nine, 7 - 3 is four,
376
+
377
+ 95
378
+ 00:04:00,000 --> 00:04:02,000
379
+ and that's what we are getting here.
380
+
381
+ 96
382
+ 00:04:02,000 --> 00:04:03,000
383
+ Everything is working fine, right?
384
+
385
+ 97
386
+ 00:04:03,000 --> 00:04:05,000
387
+ Now there are two conditions here,
388
+
389
+ 98
390
+ 00:04:05,000 --> 00:04:06,000
391
+ why we are going for inheritance.
392
+
393
+ 99
394
+ 00:04:06,000 --> 00:04:09,000
395
+ The first one is what if you want
396
+
397
+ 100
398
+ 00:04:09,000 --> 00:04:10,000
399
+ to add some extra features?
400
+
401
+ 101
402
+ 00:04:10,000 --> 00:04:13,000
403
+ You want, so let's say if someone is asking you for,
404
+
405
+ 102
406
+ 00:04:13,000 --> 00:04:14,000
407
+ "Hey, you know, Navin,
408
+
409
+ 103
410
+ 00:04:14,000 --> 00:04:17,000
411
+ I want a calculator and I want two features,
412
+
413
+ 104
414
+ 00:04:17,000 --> 00:04:19,000
415
+ addition and subtraction.
416
+
417
+ 105
418
+ 00:04:19,000 --> 00:04:20,000
419
+ What will be the cost?"
420
+
421
+ 106
422
+ 00:04:20,000 --> 00:04:22,000
423
+ I would say, "Okay, I will charge you $10."
424
+
425
+ 107
426
+ 00:04:22,000 --> 00:04:24,000
427
+ Now let's say the same person come back and say,
428
+
429
+ 108
430
+ 00:04:24,000 --> 00:04:27,000
431
+ "Hey, you know, I want a calculator which has four features,
432
+
433
+ 109
434
+ 00:04:27,000 --> 00:04:29,000
435
+ additional, subtraction, division, multiplication."
436
+
437
+ 110
438
+ 00:04:29,000 --> 00:04:33,000
439
+ And maybe at this point, I want to charge $15.
440
+
441
+ 111
442
+ 00:04:33,000 --> 00:04:35,000
443
+ Now of course, I can add those two methods here
444
+
445
+ 112
446
+ 00:04:35,000 --> 00:04:38,000
447
+ or I can create a new class, you know why?
448
+
449
+ 113
450
+ 00:04:38,000 --> 00:04:41,000
451
+ It's because if I edit the same file,
452
+
453
+ 114
454
+ 00:04:41,000 --> 00:04:42,000
455
+ if I add more features here,
456
+
457
+ 115
458
+ 00:04:42,000 --> 00:04:45,000
459
+ I can't sell calculator for $10 now.
460
+
461
+ 116
462
+ 00:04:45,000 --> 00:04:47,000
463
+ I have to make a new product for $15.
464
+
465
+ 117
466
+ 00:04:47,000 --> 00:04:49,000
467
+ I don't have calculator,
468
+
469
+ 118
470
+ 00:04:49,000 --> 00:04:51,000
471
+ I have advanced calculator which does four operations.
472
+
473
+ 119
474
+ 00:04:51,000 --> 00:04:52,000
475
+ I want both the models.
476
+
477
+ 120
478
+ 00:04:52,000 --> 00:04:57,000
479
+ I want to sell the $10 calculator and a $15 calculator.
480
+
481
+ 121
482
+ 00:04:57,000 --> 00:04:59,000
483
+ That's one reason. Okay, so let me just do that.
484
+
485
+ 122
486
+ 00:04:59,000 --> 00:05:01,000
487
+ So let me create a new calculator,
488
+
489
+ 123
490
+ 00:05:01,000 --> 00:05:04,000
491
+ and I will say this is advanced calculator,
492
+
493
+ 124
494
+ 00:05:04,000 --> 00:05:07,000
495
+ which has all the features, .java.
496
+
497
+ 125
498
+ 00:05:07,000 --> 00:05:10,000
499
+ And in this, I will basically have two more methods,
500
+
501
+ 126
502
+ 00:05:10,000 --> 00:05:15,000
503
+ which is public int multi, which will take two values,
504
+
505
+ 127
506
+ 00:05:15,000 --> 00:05:19,000
507
+ and it should return n1 into n2.
508
+
509
+ 128
510
+ 00:05:19,000 --> 00:05:21,000
511
+ And likewise, we'll have one more method here for division.
512
+
513
+ 129
514
+ 00:05:21,000 --> 00:05:26,000
515
+ So this is div and division, we have to say slash.
516
+
517
+ 130
518
+ 00:05:26,000 --> 00:05:28,000
519
+ That's it, so we got an advanced calculator,
520
+
521
+ 131
522
+ 00:05:28,000 --> 00:05:29,000
523
+ which has two features.
524
+
525
+ 132
526
+ 00:05:29,000 --> 00:05:33,000
527
+ But now if I create an object of advanced calculator now,
528
+
529
+ 133
530
+ 00:05:33,000 --> 00:05:35,000
531
+ instead of normal calculator,
532
+
533
+ 134
534
+ 00:05:35,000 --> 00:05:37,000
535
+ I can access multiplication and division.
536
+
537
+ 135
538
+ 00:05:37,000 --> 00:05:39,000
539
+ I can't access add and sub.
540
+
541
+ 136
542
+ 00:05:39,000 --> 00:05:41,000
543
+ And that's why you can see we got an error here.
544
+
545
+ 137
546
+ 00:05:41,000 --> 00:05:44,000
547
+ It says, "The method add is undefined
548
+
549
+ 138
550
+ 00:05:44,000 --> 00:05:46,000
551
+ for type advanced calculator."
552
+
553
+ 139
554
+ 00:05:46,000 --> 00:05:48,000
555
+ That means in this, we don't have add and subtract.
556
+
557
+ 140
558
+ 00:05:48,000 --> 00:05:50,000
559
+ So what do you think? What could be solution here?
560
+
561
+ 141
562
+ 00:05:50,000 --> 00:05:52,000
563
+ Think about this, so one solution,
564
+
565
+ 142
566
+ 00:05:52,000 --> 00:05:56,000
567
+ which I can see is just write those two methods here.
568
+
569
+ 143
570
+ 00:05:56,000 --> 00:05:57,000
571
+ Of course, we can do that.
572
+
573
+ 144
574
+ 00:05:57,000 --> 00:05:59,000
575
+ Okay, we can just copy and we can paste it here.
576
+
577
+ 145
578
+ 00:05:59,000 --> 00:06:01,000
579
+ But don't you think we are writing
580
+
581
+ 146
582
+ 00:06:01,000 --> 00:06:04,000
583
+ the same code again and again?
584
+
585
+ 147
586
+ 00:06:04,000 --> 00:06:05,000
587
+ Now when you repeat the same code,
588
+
589
+ 148
590
+ 00:06:05,000 --> 00:06:07,000
591
+ it is called redundancy, right?
592
+
593
+ 149
594
+ 00:06:07,000 --> 00:06:12,000
595
+ We have same code multiple times, and redundancy is a crime.
596
+
597
+ 150
598
+ 00:06:12,000 --> 00:06:13,000
599
+ So make sure that you don't repeat the values,
600
+
601
+ 151
602
+ 00:06:13,000 --> 00:06:17,000
603
+ you don't repeat the methods, definition, and classes.
604
+
605
+ 152
606
+ 00:06:17,000 --> 00:06:19,000
607
+ The point is if I don't define it here,
608
+
609
+ 153
610
+ 00:06:19,000 --> 00:06:21,000
611
+ how will I access them?
612
+
613
+ 154
614
+ 00:06:21,000 --> 00:06:24,000
615
+ That's where the in inheritance concept comes into picture.
616
+
617
+ 155
618
+ 00:06:24,000 --> 00:06:26,000
619
+ So in inheritance says, "Hey, don't worry.
620
+
621
+ 156
622
+ 00:06:26,000 --> 00:06:28,000
623
+ If you already have a class called Calc,
624
+
625
+ 157
626
+ 00:06:28,000 --> 00:06:31,000
627
+ you can simply say extends Calc, your job is done."
628
+
629
+ 158
630
+ 00:06:31,000 --> 00:06:34,000
631
+ Okay, so you simply say advanced calculator
632
+
633
+ 159
634
+ 00:06:34,000 --> 00:06:37,000
635
+ extends calculator, and now all the features
636
+
637
+ 160
638
+ 00:06:37,000 --> 00:06:40,000
639
+ of calculator comes in here.
640
+
641
+ 161
642
+ 00:06:40,000 --> 00:06:41,000
643
+ And there's one more beauty.
644
+
645
+ 162
646
+ 00:06:41,000 --> 00:06:44,000
647
+ Even if you don't have this Java file, that's fine.
648
+
649
+ 163
650
+ 00:06:44,000 --> 00:06:48,000
651
+ For inheritance, you need a class file, not a Java file.
652
+
653
+ 164
654
+ 00:06:48,000 --> 00:06:50,000
655
+ So even if you delete this, it will still work, okay?
656
+
657
+ 165
658
+ 00:06:50,000 --> 00:06:51,000
659
+ That's the first reason.
660
+
661
+ 166
662
+ 00:06:51,000 --> 00:06:53,000
663
+ Even if you don't have a code ready with you,
664
+
665
+ 167
666
+ 00:06:53,000 --> 00:06:55,000
667
+ even if you don't have a Java file,
668
+
669
+ 168
670
+ 00:06:55,000 --> 00:06:57,000
671
+ you can still use a class file.
672
+
673
+ 169
674
+ 00:06:57,000 --> 00:06:59,000
675
+ Okay, so that's the beauty of inheritance.
676
+
677
+ 170
678
+ 00:06:59,000 --> 00:07:01,000
679
+ We are simply saying extends calculator,
680
+
681
+ 171
682
+ 00:07:01,000 --> 00:07:02,000
683
+ which is this class.
684
+
685
+ 172
686
+ 00:07:02,000 --> 00:07:05,000
687
+ Now what do you think, will it work? Let's try.
688
+
689
+ 173
690
+ 00:07:05,000 --> 00:07:06,000
691
+ So you can see there's no problem,
692
+
693
+ 174
694
+ 00:07:06,000 --> 00:07:07,000
695
+ add and subtraction working.
696
+
697
+ 175
698
+ 00:07:07,000 --> 00:07:09,000
699
+ We can add some more variables here.
700
+
701
+ 176
702
+ 00:07:09,000 --> 00:07:13,000
703
+ I can just copy this code and paste, paste,
704
+
705
+ 177
706
+ 00:07:13,000 --> 00:07:14,000
707
+ not on the same line.
708
+
709
+ 178
710
+ 00:07:15,000 --> 00:07:18,000
711
+ This is my r3, this is my r4,
712
+
713
+ 179
714
+ 00:07:18,000 --> 00:07:21,000
715
+ and I can just say this is multiplication.
716
+
717
+ 180
718
+ 00:07:21,000 --> 00:07:23,000
719
+ Okay, so multiplying number,
720
+
721
+ 181
722
+ 00:07:23,000 --> 00:07:27,000
723
+ like let's say is five and three, okay?
724
+
725
+ 182
726
+ 00:07:27,000 --> 00:07:29,000
727
+ And then dividing the number,
728
+
729
+ 183
730
+ 00:07:29,000 --> 00:07:33,000
731
+ let's say 15 by 4.
732
+
733
+ 184
734
+ 00:07:33,000 --> 00:07:36,000
735
+ Let's do this, and now when I perform this operation,
736
+
737
+ 185
738
+ 00:07:36,000 --> 00:07:39,000
739
+ of course, I want to print r3 and r4 as well
740
+
741
+ 186
742
+ 00:07:39,000 --> 00:07:40,000
743
+ on the same line.
744
+
745
+ 187
746
+ 00:07:40,000 --> 00:07:43,000
747
+ I'm lazy to write multiple lines of code here, and r4.
748
+
749
+ 188
750
+ 00:07:43,000 --> 00:07:46,000
751
+ So we are printing everything in the same line.
752
+
753
+ 189
754
+ 00:07:46,000 --> 00:07:48,000
755
+ Let's try what happens.
756
+
757
+ 190
758
+ 00:07:48,000 --> 00:07:51,000
759
+ Compile, no problem. Run, it works.
760
+
761
+ 191
762
+ 00:07:51,000 --> 00:07:54,000
763
+ Can see that addition is nine, subtraction is four,
764
+
765
+ 192
766
+ 00:07:54,000 --> 00:07:56,000
767
+ multiplication is 15, if I'm not wrong, yeah,
768
+
769
+ 193
770
+ 00:07:56,000 --> 00:07:58,000
771
+ and division is three.
772
+
773
+ 194
774
+ 00:07:58,000 --> 00:08:02,000
775
+ So 15 divided by four will give you a quotient of three.
776
+
777
+ 195
778
+ 00:08:02,000 --> 00:08:03,000
779
+ Okay, cool, this is working right?
780
+
781
+ 196
782
+ 00:08:03,000 --> 00:08:06,000
783
+ So this is how we use inheritance.
784
+
785
+ 197
786
+ 00:08:06,000 --> 00:08:10,000
787
+ So important thing here is this advanced calculator
788
+
789
+ 198
790
+ 00:08:10,000 --> 00:08:11,000
791
+ here is called a subclass.
792
+
793
+ 199
794
+ 00:08:11,000 --> 00:08:14,000
795
+ This calculator here is called a superclass.
796
+
797
+ 200
798
+ 00:08:14,000 --> 00:08:18,000
799
+ And to inherit, we use a keyword called extends, okay?
800
+
801
+ 201
802
+ 00:08:18,000 --> 00:08:22,000
803
+ And this is basically a relationship of is-a.
804
+
805
+ 202
806
+ 00:08:22,000 --> 00:08:26,000
807
+ Advanced calculator is a calculator,
808
+
809
+ 203
810
+ 00:08:26,000 --> 00:08:28,000
811
+ and that's why we say is, an important word there.
812
+
813
+ 204
814
+ 00:08:28,000 --> 00:08:31,000
815
+ Cool, can I have multiple classes in hitting each other?
816
+
817
+ 205
818
+ 00:08:31,000 --> 00:08:33,000
819
+ We can, that's we'll see in the upcoming videos.
820
+
821
+ 206
822
+ 00:08:33,000 --> 00:08:36,000
823
+ At this point, we just went for a simple inheritance
824
+
825
+ 207
826
+ 00:08:36,000 --> 00:08:39,000
827
+ where we just use the feature of a superclass.
828
+
829
+ 208
830
+ 00:08:39,000 --> 00:08:41,000
831
+ You can say parent has all these two features,
832
+
833
+ 209
834
+ 00:08:41,000 --> 00:08:44,000
835
+ child is just extending it or using it.
836
+
837
+ 210
838
+ 00:08:44,000 --> 00:08:46,000
839
+ I can say this is nepotism.
840
+
841
+ 211
842
+ 00:08:46,000 --> 00:08:47,000
843
+ (laughs) So that's it from this video.
844
+
845
+ 212
846
+ 00:08:47,000 --> 00:08:50,000
847
+ I hope you enjoyed and see you in the next video.
848
+
02 - Core Java/052 Need of Inheritance_en.srt ADDED
@@ -0,0 +1,664 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (bright music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: Now let's talk more about OOPs concept.
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:09,000
11
+ Now, OOPs basically stands for Object Oriented Programming.
12
+
13
+ 4
14
+ 00:00:09,000 --> 00:00:10,000
15
+ Now, in Object Oriented Programming,
16
+
17
+ 5
18
+ 00:00:10,000 --> 00:00:14,000
19
+ we have talked about Object Class Encapsulation, right?
20
+
21
+ 6
22
+ 00:00:14,000 --> 00:00:16,000
23
+ Now let's talk more concepts.
24
+
25
+ 7
26
+ 00:00:16,000 --> 00:00:17,000
27
+ Now, one of the most important thing
28
+
29
+ 8
30
+ 00:00:17,000 --> 00:00:21,000
31
+ in the concept of OOPs is called inheritance.
32
+
33
+ 9
34
+ 00:00:21,000 --> 00:00:23,000
35
+ Now, what is inheritance?
36
+
37
+ 10
38
+ 00:00:23,000 --> 00:00:25,000
39
+ Now, there are two words actually here,
40
+
41
+ 11
42
+ 00:00:25,000 --> 00:00:30,000
43
+ which will confuse people is, "is" and "has."
44
+
45
+ 12
46
+ 00:00:30,000 --> 00:00:32,000
47
+ Now what these two words are.
48
+
49
+ 13
50
+ 00:00:32,000 --> 00:00:33,000
51
+ Now, if we talk about a computer,
52
+
53
+ 14
54
+ 00:00:33,000 --> 00:00:36,000
55
+ now, of course, computer itself is abstract concept, right?
56
+
57
+ 15
58
+ 00:00:36,000 --> 00:00:39,000
59
+ Now a computer can be a laptop, a computer can be a desktop,
60
+
61
+ 16
62
+ 00:00:39,000 --> 00:00:41,000
63
+ a computer can be a mobile phone.
64
+
65
+ 17
66
+ 00:00:41,000 --> 00:00:42,000
67
+ That's right.
68
+
69
+ 18
70
+ 00:00:42,000 --> 00:00:43,000
71
+ So even if you talk about this phone,
72
+
73
+ 19
74
+ 00:00:43,000 --> 00:00:47,000
75
+ this is a computer in the form of mobile phone, of course.
76
+
77
+ 20
78
+ 00:00:47,000 --> 00:00:49,000
79
+ And the computer itself is an abstract concept.
80
+
81
+ 21
82
+ 00:00:49,000 --> 00:00:50,000
83
+ No one owns a computer.
84
+
85
+ 22
86
+ 00:00:50,000 --> 00:00:52,000
87
+ You basically buy a hardware,
88
+
89
+ 23
90
+ 00:00:52,000 --> 00:00:54,000
91
+ which can be a desktop, laptop, or a phone.
92
+
93
+ 24
94
+ 00:00:54,000 --> 00:00:57,000
95
+ Now, can I say that if you talk about a desktop,
96
+
97
+ 25
98
+ 00:00:57,000 --> 00:00:58,000
99
+ so I'm talking about a desktop, which is this big,
100
+
101
+ 26
102
+ 00:00:58,000 --> 00:01:01,000
103
+ and it will have certain parts, right?
104
+
105
+ 27
106
+ 00:01:01,000 --> 00:01:02,000
107
+ A desktop will have a motherboard,
108
+
109
+ 28
110
+ 00:01:02,000 --> 00:01:05,000
111
+ a desktop will have a hard drive, CPU, ram.
112
+
113
+ 29
114
+ 00:01:05,000 --> 00:01:06,000
115
+ So when you talk about this thing,
116
+
117
+ 30
118
+ 00:01:06,000 --> 00:01:10,000
119
+ it is desktop has a motherboard,
120
+
121
+ 31
122
+ 00:01:10,000 --> 00:01:14,000
123
+ desktop has a hard drive, it has a CPU, right?
124
+
125
+ 32
126
+ 00:01:14,000 --> 00:01:16,000
127
+ So the important keyword there is "has."
128
+
129
+ 33
130
+ 00:01:16,000 --> 00:01:19,000
131
+ If we talk about a house, a house will have a TV,
132
+
133
+ 34
134
+ 00:01:19,000 --> 00:01:22,000
135
+ a house will have a sofa, AC, bed.
136
+
137
+ 35
138
+ 00:01:22,000 --> 00:01:25,000
139
+ So all those things, what a house has, right?
140
+
141
+ 36
142
+ 00:01:25,000 --> 00:01:27,000
143
+ So "has" is an important word.
144
+
145
+ 37
146
+ 00:01:27,000 --> 00:01:28,000
147
+ But at this point, let's not focus on "has."
148
+
149
+ 38
150
+ 00:01:28,000 --> 00:01:30,000
151
+ In this video, let's talk about "is."
152
+
153
+ 39
154
+ 00:01:30,000 --> 00:01:32,000
155
+ Now what is, is, is.
156
+
157
+ 40
158
+ 00:01:32,000 --> 00:01:34,000
159
+ Okay, so example, if we talk about a laptop,
160
+
161
+ 41
162
+ 00:01:34,000 --> 00:01:38,000
163
+ so can we say a laptop is a computer?
164
+
165
+ 42
166
+ 00:01:38,000 --> 00:01:42,000
167
+ So what it means is, laptop got it features from a computer.
168
+
169
+ 43
170
+ 00:01:42,000 --> 00:01:44,000
171
+ So can we take another example here?
172
+
173
+ 44
174
+ 00:01:44,000 --> 00:01:46,000
175
+ If we talk about a car, let's say.
176
+
177
+ 45
178
+ 00:01:46,000 --> 00:01:48,000
179
+ Let's say if we talk about a Fortuner,
180
+
181
+ 46
182
+ 00:01:48,000 --> 00:01:49,000
183
+ which is very famous in India.
184
+
185
+ 47
186
+ 00:01:49,000 --> 00:01:51,000
187
+ So this car is actually a car, right?
188
+
189
+ 48
190
+ 00:01:51,000 --> 00:01:54,000
191
+ So Fortuner is a car.
192
+
193
+ 49
194
+ 00:01:54,000 --> 00:01:55,000
195
+ So that's how you represent something.
196
+
197
+ 50
198
+ 00:01:55,000 --> 00:01:58,000
199
+ You represent a device or a physical entity
200
+
201
+ 51
202
+ 00:01:58,000 --> 00:02:00,000
203
+ by referring to its upper model,
204
+
205
+ 52
206
+ 00:02:00,000 --> 00:02:02,000
207
+ or you try to take the features of it.
208
+
209
+ 53
210
+ 00:02:02,000 --> 00:02:04,000
211
+ Now, coming back to the Inheritance concept,
212
+
213
+ 54
214
+ 00:02:04,000 --> 00:02:06,000
215
+ in real world example,
216
+
217
+ 55
218
+ 00:02:06,000 --> 00:02:08,000
219
+ let's say if we talk about the human world,
220
+
221
+ 56
222
+ 00:02:08,000 --> 00:02:10,000
223
+ you know, when I was in my 10th standard,
224
+
225
+ 57
226
+ 00:02:10,000 --> 00:02:12,000
227
+ so just for the example, okay, not that important,
228
+
229
+ 58
230
+ 00:02:12,000 --> 00:02:16,000
231
+ but when I was in my 10th standard, I did my 10th in 2005.
232
+
233
+ 59
234
+ 00:02:16,000 --> 00:02:20,000
235
+ At that point, Nokia released a lot of smartphones, right?
236
+
237
+ 60
238
+ 00:02:20,000 --> 00:02:21,000
239
+ Of course, Nokia is not there anymore,
240
+
241
+ 61
242
+ 00:02:21,000 --> 00:02:25,000
243
+ but Nokia was one of the most important factor
244
+
245
+ 62
246
+ 00:02:25,000 --> 00:02:26,000
247
+ in the smartphone industry.
248
+
249
+ 63
250
+ 00:02:26,000 --> 00:02:28,000
251
+ Now, when they came up with a smartphone,
252
+
253
+ 64
254
+ 00:02:28,000 --> 00:02:31,000
255
+ one of the most famous smartphone which they built is 6600.
256
+
257
+ 65
258
+ 00:02:31,000 --> 00:02:33,000
259
+ I'm not sure if you have seen that.
260
+
261
+ 66
262
+ 00:02:33,000 --> 00:02:34,000
263
+ I'm not even sure if you're that old.
264
+
265
+ 67
266
+ 00:02:34,000 --> 00:02:37,000
267
+ Maybe you were not even born in that year.
268
+
269
+ 68
270
+ 00:02:37,000 --> 00:02:39,000
271
+ But yeah, so it was 6600. Amazing phone.
272
+
273
+ 69
274
+ 00:02:39,000 --> 00:02:42,000
275
+ If you can just search on Google, Nokia 6600,
276
+
277
+ 70
278
+ 00:02:42,000 --> 00:02:44,000
279
+ you will see that phone.
280
+
281
+ 71
282
+ 00:02:44,000 --> 00:02:46,000
283
+ Now, a lot of my friends were having that phone.
284
+
285
+ 72
286
+ 00:02:46,000 --> 00:02:47,000
287
+ It was costly phone at that point.
288
+
289
+ 73
290
+ 00:02:47,000 --> 00:02:49,000
291
+ It was around 10,000 rupees.
292
+
293
+ 74
294
+ 00:02:49,000 --> 00:02:51,000
295
+ And I was not having any phone.
296
+
297
+ 75
298
+ 00:02:51,000 --> 00:02:52,000
299
+ So they used to ask me, "Hey, which phone you have?"
300
+
301
+ 76
302
+ 00:02:52,000 --> 00:02:54,000
303
+ I used to say, "Hey, I don't have a phone."
304
+
305
+ 77
306
+ 00:02:54,000 --> 00:02:58,000
307
+ But then I realized, hey, till when I will say that.
308
+
309
+ 78
310
+ 00:02:58,000 --> 00:02:59,000
311
+ The thing is,
312
+
313
+ 79
314
+ 00:02:59,000 --> 00:03:01,000
315
+ next time when people used to ask me which phone I have,
316
+
317
+ 80
318
+ 00:03:01,000 --> 00:03:04,000
319
+ I used to say I have 3310.
320
+
321
+ 81
322
+ 00:03:04,000 --> 00:03:05,000
323
+ Now, I was not having any phone.
324
+
325
+ 82
326
+ 00:03:05,000 --> 00:03:07,000
327
+ Now, this is my father's phone,
328
+
329
+ 83
330
+ 00:03:07,000 --> 00:03:09,000
331
+ and we know the concept, right?
332
+
333
+ 84
334
+ 00:03:09,000 --> 00:03:10,000
335
+ Father's phone is yours phone.
336
+
337
+ 85
338
+ 00:03:10,000 --> 00:03:12,000
339
+ In fact, in general, we say,
340
+
341
+ 86
342
+ 00:03:12,000 --> 00:03:14,000
343
+ our parents' property, it's your property.
344
+
345
+ 87
346
+ 00:03:14,000 --> 00:03:16,000
347
+ Whatever they own, it's yours.
348
+
349
+ 88
350
+ 00:03:16,000 --> 00:03:17,000
351
+ I don't believe in that, okay?
352
+
353
+ 89
354
+ 00:03:17,000 --> 00:03:20,000
355
+ I'm not a big fan of inheritance or nepotism,
356
+
357
+ 90
358
+ 00:03:20,000 --> 00:03:22,000
359
+ but yeah, you get everything.
360
+
361
+ 91
362
+ 00:03:22,000 --> 00:03:24,000
363
+ So I used to say I have that phone.
364
+
365
+ 92
366
+ 00:03:24,000 --> 00:03:25,000
367
+ Okay, so this is inheritance.
368
+
369
+ 93
370
+ 00:03:25,000 --> 00:03:27,000
371
+ Now, how will you use this concept in programming?
372
+
373
+ 94
374
+ 00:03:27,000 --> 00:03:29,000
375
+ Now in Java, what you have
376
+
377
+ 95
378
+ 00:03:29,000 --> 00:03:30,000
379
+ is you have different classes, right?
380
+
381
+ 96
382
+ 00:03:30,000 --> 00:03:32,000
383
+ Example, if you create a simple class here.
384
+
385
+ 97
386
+ 00:03:32,000 --> 00:03:33,000
387
+ Let me get a very simple class.
388
+
389
+ 98
390
+ 00:03:33,000 --> 00:03:36,000
391
+ Let's say we have a class here called Calculator.
392
+
393
+ 99
394
+ 00:03:36,000 --> 00:03:38,000
395
+ Now what features a calculator will have?
396
+
397
+ 100
398
+ 00:03:38,000 --> 00:03:41,000
399
+ A calculator will have some variables here,
400
+
401
+ 101
402
+ 00:03:41,000 --> 00:03:42,000
403
+ and then it will have some methods.
404
+
405
+ 102
406
+ 00:03:42,000 --> 00:03:46,000
407
+ Let's say method is add, a method is sub, okay?
408
+
409
+ 103
410
+ 00:03:46,000 --> 00:03:48,000
411
+ And then method is multi.
412
+
413
+ 104
414
+ 00:03:48,000 --> 00:03:50,000
415
+ So we have different methods here.
416
+
417
+ 105
418
+ 00:03:50,000 --> 00:03:51,000
419
+ And let's also have division.
420
+
421
+ 106
422
+ 00:03:51,000 --> 00:03:53,000
423
+ Why division should be left there?
424
+
425
+ 107
426
+ 00:03:53,000 --> 00:03:56,000
427
+ So we have all these methods, right? And it is working.
428
+
429
+ 108
430
+ 00:03:56,000 --> 00:03:58,000
431
+ So you can basically create object of Calculator,
432
+
433
+ 109
434
+ 00:03:58,000 --> 00:03:59,000
435
+ and you can access all these methods.
436
+
437
+ 110
438
+ 00:03:59,000 --> 00:04:00,000
439
+ No harm in that.
440
+
441
+ 111
442
+ 00:04:00,000 --> 00:04:04,000
443
+ But what if you want to create a advanced calculator?
444
+
445
+ 112
446
+ 00:04:04,000 --> 00:04:06,000
447
+ Now of course, let's say if someone comes to you
448
+
449
+ 113
450
+ 00:04:06,000 --> 00:04:09,000
451
+ and say, "Hey, you know, you made a awesome calculator
452
+
453
+ 114
454
+ 00:04:09,000 --> 00:04:12,000
455
+ and now I want you to create a scientific calculator
456
+
457
+ 115
458
+ 00:04:12,000 --> 00:04:14,000
459
+ or advanced calculator."
460
+
461
+ 116
462
+ 00:04:14,000 --> 00:04:15,000
463
+ Now you have a choice.
464
+
465
+ 117
466
+ 00:04:15,000 --> 00:04:18,000
467
+ You can edit the same class, but there's only one thing.
468
+
469
+ 118
470
+ 00:04:18,000 --> 00:04:20,000
471
+ What if you enhance the same class?
472
+
473
+ 119
474
+ 00:04:20,000 --> 00:04:21,000
475
+ You add some more methods here.
476
+
477
+ 120
478
+ 00:04:21,000 --> 00:04:25,000
479
+ Now you want to give Calculator to someone,
480
+
481
+ 121
482
+ 00:04:25,000 --> 00:04:27,000
483
+ someone asking you for the Calculator object.
484
+
485
+ 122
486
+ 00:04:27,000 --> 00:04:28,000
487
+ They basically access all the basic features
488
+
489
+ 123
490
+ 00:04:28,000 --> 00:04:30,000
491
+ and advanced features, as well.
492
+
493
+ 124
494
+ 00:04:30,000 --> 00:04:33,000
495
+ So it is good to create a separate class, okay?
496
+
497
+ 125
498
+ 00:04:33,000 --> 00:04:34,000
499
+ So you can get a separate class,
500
+
501
+ 126
502
+ 00:04:34,000 --> 00:04:37,000
503
+ and you can say Advanced Calculator, right?
504
+
505
+ 127
506
+ 00:04:37,000 --> 00:04:40,000
507
+ And then this will have all the advanced features.
508
+
509
+ 128
510
+ 00:04:40,000 --> 00:04:41,000
511
+ Of course, it will have all the basic features,
512
+
513
+ 129
514
+ 00:04:41,000 --> 00:04:43,000
515
+ and it will have the advanced features, as well.
516
+
517
+ 130
518
+ 00:04:43,000 --> 00:04:46,000
519
+ So we have basic features, advanced features both.
520
+
521
+ 131
522
+ 00:04:46,000 --> 00:04:47,000
523
+ But don't you think
524
+
525
+ 132
526
+ 00:04:47,000 --> 00:04:51,000
527
+ you need to define these basic features again and again?
528
+
529
+ 133
530
+ 00:04:51,000 --> 00:04:54,000
531
+ Why? We already have those features here, right?
532
+
533
+ 134
534
+ 00:04:54,000 --> 00:04:56,000
535
+ We already have those features here.
536
+
537
+ 135
538
+ 00:04:56,000 --> 00:05:01,000
539
+ Can I just use those features in my new Advanced Calculator?
540
+
541
+ 136
542
+ 00:05:02,000 --> 00:05:04,000
543
+ So what I'm saying is basically
544
+
545
+ 137
546
+ 00:05:04,000 --> 00:05:07,000
547
+ this Advanced Calculator is going to inherit
548
+
549
+ 138
550
+ 00:05:07,000 --> 00:05:12,000
551
+ the properties and features from Calculator.
552
+
553
+ 139
554
+ 00:05:12,000 --> 00:05:15,000
555
+ So I can also say Advanced Calculator is a Calculator,
556
+
557
+ 140
558
+ 00:05:15,000 --> 00:05:17,000
559
+ and it will get all the features of Calculator.
560
+
561
+ 141
562
+ 00:05:17,000 --> 00:05:20,000
563
+ Okay, it will make much more sense once we start coding.
564
+
565
+ 142
566
+ 00:05:20,000 --> 00:05:24,000
567
+ But what we are doing here is, we are doing inheritance.
568
+
569
+ 143
570
+ 00:05:24,000 --> 00:05:27,000
571
+ So basically, inheritance is a very important feature,
572
+
573
+ 144
574
+ 00:05:27,000 --> 00:05:29,000
575
+ using which you can just copy the feature
576
+
577
+ 145
578
+ 00:05:29,000 --> 00:05:31,000
579
+ from the upper class.
580
+
581
+ 146
582
+ 00:05:31,000 --> 00:05:32,000
583
+ Can I say this is a parent class?
584
+
585
+ 147
586
+ 00:05:32,000 --> 00:05:37,000
587
+ So this is a parent class, and this is a child class
588
+
589
+ 148
590
+ 00:05:37,000 --> 00:05:39,000
591
+ because child class is accessing
592
+
593
+ 149
594
+ 00:05:39,000 --> 00:05:41,000
595
+ the feature of parent class, okay?
596
+
597
+ 150
598
+ 00:05:41,000 --> 00:05:44,000
599
+ So whatever I earn, it's my money,
600
+
601
+ 151
602
+ 00:05:44,000 --> 00:05:45,000
603
+ plus my parent's money is my money.
604
+
605
+ 152
606
+ 00:05:45,000 --> 00:05:46,000
607
+ That's how the system works, right?
608
+
609
+ 153
610
+ 00:05:46,000 --> 00:05:49,000
611
+ We can also say this is a super class.
612
+
613
+ 154
614
+ 00:05:49,000 --> 00:05:51,000
615
+ We have different words for it. That's it.
616
+
617
+ 155
618
+ 00:05:51,000 --> 00:05:54,000
619
+ And we can say this is a subclass.
620
+
621
+ 156
622
+ 00:05:54,000 --> 00:05:57,000
623
+ We can also say this is a base class, base.
624
+
625
+ 157
626
+ 00:05:57,000 --> 00:06:00,000
627
+ And this is a derived class.
628
+
629
+ 158
630
+ 00:06:00,000 --> 00:06:02,000
631
+ So it depends upon how you represent that.
632
+
633
+ 159
634
+ 00:06:02,000 --> 00:06:04,000
635
+ If you say this is a parent class,
636
+
637
+ 160
638
+ 00:06:04,000 --> 00:06:06,000
639
+ then you have to say it's a child class.
640
+
641
+ 161
642
+ 00:06:06,000 --> 00:06:09,000
643
+ If you say that's a super class, then it becomes a subclass.
644
+
645
+ 162
646
+ 00:06:09,000 --> 00:06:09,000
647
+ If you say this is a base class,
648
+
649
+ 163
650
+ 00:06:09,000 --> 00:06:11,000
651
+ you have to say this is a derived class.
652
+
653
+ 164
654
+ 00:06:11,000 --> 00:06:13,000
655
+ That's how it works, okay?
656
+
657
+ 165
658
+ 00:06:13,000 --> 00:06:16,000
659
+ Now, this is what inheritance is.
660
+
661
+ 166
662
+ 00:06:16,000 --> 00:06:19,000
663
+ Now we'll try to implement this in code in the next video.
664
+
02 - Core Java/052 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/053 Single and Multilevel inheritance_en.srt ADDED
@@ -0,0 +1,396 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (piano music opening)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: So basically we were able to do advanced calculator,
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:08,000
11
+ which uses a feature of calculator, right?
12
+
13
+ 4
14
+ 00:00:08,000 --> 00:00:10,000
15
+ So this is extends.
16
+
17
+ 5
18
+ 00:00:10,000 --> 00:00:12,000
19
+ Now what if in future,
20
+
21
+ 6
22
+ 00:00:12,000 --> 00:00:15,000
23
+ let's say we got one more requirement, we want to build a,
24
+
25
+ 7
26
+ 00:00:15,000 --> 00:00:16,000
27
+ let's say scientific calculator
28
+
29
+ 8
30
+ 00:00:16,000 --> 00:00:17,000
31
+ and I don't know the operation,
32
+
33
+ 9
34
+ 00:00:17,000 --> 00:00:20,000
35
+ so I will just say Very Advanced Calculator.
36
+
37
+ 10
38
+ 00:00:20,000 --> 00:00:23,000
39
+ I'm very bad with names, so I will just use this
40
+
41
+ 11
42
+ 00:00:23,000 --> 00:00:26,000
43
+ and this advanced calculator will have extra feature.
44
+
45
+ 12
46
+ 00:00:26,000 --> 00:00:27,000
47
+ Let's say it also has a feature
48
+
49
+ 13
50
+ 00:00:27,000 --> 00:00:31,000
51
+ of finding the power of a number.
52
+
53
+ 14
54
+ 00:00:31,000 --> 00:00:33,000
55
+ Okay? So let's say public int,
56
+
57
+ 15
58
+ 00:00:33,000 --> 00:00:34,000
59
+ I can simply say, yeah, power.
60
+
61
+ 16
62
+ 00:00:34,000 --> 00:00:37,000
63
+ Now what we power, let's say three is two. I wanna do that.
64
+
65
+ 17
66
+ 00:00:37,000 --> 00:00:38,000
67
+ So it'll take two numbers.
68
+
69
+ 18
70
+ 00:00:38,000 --> 00:00:40,000
71
+ The first value N1,
72
+
73
+ 19
74
+ 00:00:40,000 --> 00:00:43,000
75
+ and I also want a power, let's say N2
76
+
77
+ 20
78
+ 00:00:43,000 --> 00:00:44,000
79
+ and let's say this will return, okay?
80
+
81
+ 21
82
+ 00:00:44,000 --> 00:00:47,000
83
+ How do we do the power? So basically we have a math class.
84
+
85
+ 22
86
+ 00:00:47,000 --> 00:00:49,000
87
+ I can just simply use it.
88
+
89
+ 23
90
+ 00:00:49,000 --> 00:00:52,000
91
+ Math., yeah, we have a function of power.
92
+
93
+ 24
94
+ 00:00:52,000 --> 00:00:55,000
95
+ Just take double value, but that's fine. I will just pass.
96
+
97
+ 25
98
+ 00:00:55,000 --> 00:00:57,000
99
+ Integer double also takes integer value.
100
+
101
+ 26
102
+ 00:00:57,000 --> 00:00:58,000
103
+ N1, N2.
104
+
105
+ 27
106
+ 00:00:58,000 --> 00:01:01,000
107
+ And the problem is it also returns the double value.
108
+
109
+ 28
110
+ 00:01:01,000 --> 00:01:03,000
111
+ If you can see, power returns are double value.
112
+
113
+ 29
114
+ 00:01:03,000 --> 00:01:06,000
115
+ So what I will do is, let me return double value, okay?
116
+
117
+ 30
118
+ 00:01:06,000 --> 00:01:08,000
119
+ So you have a choice, you can return double value
120
+
121
+ 31
122
+ 00:01:08,000 --> 00:01:12,000
123
+ or you can just typecast it with int and you can do that.
124
+
125
+ 32
126
+ 00:01:12,000 --> 00:01:13,000
127
+ Otherwise double is okay.
128
+
129
+ 33
130
+ 00:01:13,000 --> 00:01:14,000
131
+ So you can see we have a power function,
132
+
133
+ 34
134
+ 00:01:14,000 --> 00:01:17,000
135
+ which takes this method and it calculates.
136
+
137
+ 35
138
+ 00:01:17,000 --> 00:01:19,000
139
+ Now the thing is, if I want to create
140
+
141
+ 36
142
+ 00:01:19,000 --> 00:01:21,000
143
+ object of power, well I will do that.
144
+
145
+ 37
146
+ 00:01:21,000 --> 00:01:22,000
147
+ I will just create that in demo.
148
+
149
+ 38
150
+ 00:01:22,000 --> 00:01:24,000
151
+ I will say, hey, if someone wants
152
+
153
+ 39
154
+ 00:01:24,000 --> 00:01:28,000
155
+ to try very advanced calculator, they can do that.
156
+
157
+ 40
158
+ 00:01:28,000 --> 00:01:30,000
159
+ Okay? It is just that very advanced calculator.
160
+
161
+ 41
162
+ 00:01:30,000 --> 00:01:33,000
163
+ If you can see, we don't have any of the methods. Okay?
164
+
165
+ 42
166
+ 00:01:33,000 --> 00:01:36,000
167
+ Now that's an issue right?
168
+
169
+ 43
170
+ 00:01:36,000 --> 00:01:38,000
171
+ Now I know in your mind you have a solution, right?
172
+
173
+ 44
174
+ 00:01:38,000 --> 00:01:40,000
175
+ You have a choice. You can just add,
176
+
177
+ 45
178
+ 00:01:40,000 --> 00:01:42,000
179
+ you can just type all these methods here
180
+
181
+ 46
182
+ 00:01:42,000 --> 00:01:46,000
183
+ or we can come back here and say extends.
184
+
185
+ 47
186
+ 00:01:46,000 --> 00:01:47,000
187
+ Okay? Now it'll extends what?.
188
+
189
+ 48
190
+ 00:01:47,000 --> 00:01:49,000
191
+ We can also say calculator,
192
+
193
+ 49
194
+ 00:01:49,000 --> 00:01:52,000
195
+ but then this will only have addition, subtraction,
196
+
197
+ 50
198
+ 00:01:52,000 --> 00:01:53,000
199
+ division, multiplication,
200
+
201
+ 51
202
+ 00:01:53,000 --> 00:01:55,000
203
+ but not the feature of advanced calculator,
204
+
205
+ 52
206
+ 00:01:55,000 --> 00:01:57,000
207
+ which is, oh, it'll not have this two as well,
208
+
209
+ 53
210
+ 00:01:57,000 --> 00:02:00,000
211
+ because this two is there in advanced calculator,
212
+
213
+ 54
214
+ 00:02:00,000 --> 00:02:01,000
215
+ it'll only have add and sub.
216
+
217
+ 55
218
+ 00:02:01,000 --> 00:02:04,000
219
+ You can see multi and division not found.
220
+
221
+ 56
222
+ 00:02:04,000 --> 00:02:05,000
223
+ In fact, you know, I should also have R3.
224
+
225
+ 57
226
+ 00:02:05,000 --> 00:02:09,000
227
+ In fact, this should be of type double, double R5 equal
228
+
229
+ 58
230
+ 00:02:09,000 --> 00:02:14,000
231
+ to OBJ.power by passing two values.
232
+
233
+ 59
234
+ 00:02:14,000 --> 00:02:16,000
235
+ One is, let's say four (indistinct),
236
+
237
+ 60
238
+ 00:02:16,000 --> 00:02:19,000
239
+ at least we know the output should be 16.
240
+
241
+ 61
242
+ 00:02:19,000 --> 00:02:22,000
243
+ And I also want to print R5.
244
+
245
+ 62
246
+ 00:02:22,000 --> 00:02:24,000
247
+ Oh, we are printing everything in one line. Great.
248
+
249
+ 63
250
+ 00:02:24,000 --> 00:02:26,000
251
+ And you can see multi and division are not working.
252
+
253
+ 64
254
+ 00:02:26,000 --> 00:02:28,000
255
+ So if you want to make it work,
256
+
257
+ 65
258
+ 00:02:28,000 --> 00:02:29,000
259
+ you can't just extends calculator, you have
260
+
261
+ 66
262
+ 00:02:29,000 --> 00:02:32,000
263
+ to extends advanced calculator.
264
+
265
+ 67
266
+ 00:02:32,000 --> 00:02:34,000
267
+ So you can see we have multiple hierarchy here.
268
+
269
+ 68
270
+ 00:02:34,000 --> 00:02:35,000
271
+ So very advanced calculator is
272
+
273
+ 69
274
+ 00:02:35,000 --> 00:02:37,000
275
+ extending advanced calculator.
276
+
277
+ 70
278
+ 00:02:37,000 --> 00:02:39,000
279
+ Advanced calculator is extending calculator.
280
+
281
+ 71
282
+ 00:02:39,000 --> 00:02:42,000
283
+ So if you try to compile this code, let's say if this works,
284
+
285
+ 72
286
+ 00:02:42,000 --> 00:02:45,000
287
+ compile and run, you can see it's working.
288
+
289
+ 73
290
+ 00:02:45,000 --> 00:02:48,000
291
+ You got 16 at the end, you got 0.0
292
+
293
+ 74
294
+ 00:02:48,000 --> 00:02:51,000
295
+ because we are returning a double value.
296
+
297
+ 75
298
+ 00:02:51,000 --> 00:02:53,000
299
+ This works. So if you're trying to imagine this,
300
+
301
+ 76
302
+ 00:02:53,000 --> 00:02:57,000
303
+ what we are doing is, so we have a calculator
304
+
305
+ 77
306
+ 00:02:57,000 --> 00:03:00,000
307
+ and then advanced calculator is extending calculator.
308
+
309
+ 78
310
+ 00:03:00,000 --> 00:03:04,000
311
+ And then we got very advanced calculator is extending
312
+
313
+ 79
314
+ 00:03:04,000 --> 00:03:05,000
315
+ from advanced calculator.
316
+
317
+ 80
318
+ 00:03:05,000 --> 00:03:08,000
319
+ Now, this is when you are saying multiple,
320
+
321
+ 81
322
+ 00:03:08,000 --> 00:03:10,000
323
+ where we are doing inheritance, right?
324
+
325
+ 82
326
+ 00:03:10,000 --> 00:03:14,000
327
+ So this is called multilevel inheritance.
328
+
329
+ 83
330
+ 00:03:14,000 --> 00:03:17,000
331
+ So basically we have multilevel inheritance here
332
+
333
+ 84
334
+ 00:03:17,000 --> 00:03:18,000
335
+ because we have multiple level,
336
+
337
+ 85
338
+ 00:03:18,000 --> 00:03:22,000
339
+ but in the early example we were having a just two, right?
340
+
341
+ 86
342
+ 00:03:22,000 --> 00:03:23,000
343
+ So we were having this two.
344
+
345
+ 87
346
+ 00:03:23,000 --> 00:03:26,000
347
+ Now when you say only two classes, this is called,
348
+
349
+ 88
350
+ 00:03:27,000 --> 00:03:30,000
351
+ single level inheritance,
352
+
353
+ 89
354
+ 00:03:30,000 --> 00:03:32,000
355
+ and I know I became a doctor there,
356
+
357
+ 90
358
+ 00:03:32,000 --> 00:03:34,000
359
+ but you got the point, right?
360
+
361
+ 91
362
+ 00:03:34,000 --> 00:03:35,000
363
+ So if you have multiple layers,
364
+
365
+ 92
366
+ 00:03:35,000 --> 00:03:37,000
367
+ that is multi-level inheritance.
368
+
369
+ 93
370
+ 00:03:37,000 --> 00:03:39,000
371
+ And when you say single, that is single,
372
+
373
+ 94
374
+ 00:03:39,000 --> 00:03:40,000
375
+ when you have only two classes.
376
+
377
+ 95
378
+ 00:03:40,000 --> 00:03:44,000
379
+ Now the very advanced calculator here is taking the feature
380
+
381
+ 96
382
+ 00:03:44,000 --> 00:03:45,000
383
+ from advanced calculator.
384
+
385
+ 97
386
+ 00:03:45,000 --> 00:03:47,000
387
+ Advanced calculator is taking the feature from calculator.
388
+
389
+ 98
390
+ 00:03:47,000 --> 00:03:50,000
391
+ So by default, all the calc. stuff will come to
392
+
393
+ 99
394
+ 00:03:50,000 --> 00:03:52,000
395
+ very advanced and that is multi-level.
396
+
02 - Core Java/053 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/054 Multiple Inheritance_en.srt ADDED
@@ -0,0 +1,656 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (gentle piano music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:04,000
7
+ -: So in the last video we have talked
8
+
9
+ 3
10
+ 00:00:04,000 --> 00:00:06,000
11
+ about what is single level inheritance,
12
+
13
+ 4
14
+ 00:00:06,000 --> 00:00:08,000
15
+ and then we have talked about multi-level, right?
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:09,000
19
+ Now what is multi-level?
20
+
21
+ 6
22
+ 00:00:09,000 --> 00:00:11,000
23
+ So when you have the class,
24
+
25
+ 7
26
+ 00:00:11,000 --> 00:00:13,000
27
+ which is getting inherited by someone else
28
+
29
+ 8
30
+ 00:00:13,000 --> 00:00:15,000
31
+ and then something else is getting inherited
32
+
33
+ 9
34
+ 00:00:15,000 --> 00:00:16,000
35
+ by something else.
36
+
37
+ 10
38
+ 00:00:16,000 --> 00:00:18,000
39
+ It is multi-level.
40
+
41
+ 11
42
+ 00:00:18,000 --> 00:00:21,000
43
+ Now, can we have a different structure here?
44
+
45
+ 12
46
+ 00:00:21,000 --> 00:00:22,000
47
+ Let's take one more example.
48
+
49
+ 13
50
+ 00:00:22,000 --> 00:00:26,000
51
+ So if you say we have A, we have B and we have C.
52
+
53
+ 14
54
+ 00:00:26,000 --> 00:00:28,000
55
+ Now this is multi-level, right?
56
+
57
+ 15
58
+ 00:00:28,000 --> 00:00:31,000
59
+ And of course when you have A and B, that's it.
60
+
61
+ 16
62
+ 00:00:31,000 --> 00:00:33,000
63
+ This is single level.
64
+
65
+ 17
66
+ 00:00:33,000 --> 00:00:37,000
67
+ But what if you have A and B, and then you have C,
68
+
69
+ 18
70
+ 00:00:37,000 --> 00:00:41,000
71
+ where your A is your parent.
72
+
73
+ 19
74
+ 00:00:41,000 --> 00:00:42,000
75
+ In fact, in this situation as well,
76
+
77
+ 20
78
+ 00:00:42,000 --> 00:00:44,000
79
+ if you try to expand this one.
80
+
81
+ 21
82
+ 00:00:44,000 --> 00:00:49,000
83
+ Here as well, we have this A as a parent,
84
+
85
+ 22
86
+ 00:00:50,000 --> 00:00:53,000
87
+ and then this B becomes a child.
88
+
89
+ 23
90
+ 00:00:53,000 --> 00:00:55,000
91
+ Now, B becomes child for A,
92
+
93
+ 24
94
+ 00:00:55,000 --> 00:00:59,000
95
+ but then B is also a parent for C, right?
96
+
97
+ 25
98
+ 00:00:59,000 --> 00:01:00,000
99
+ So C becomes child here.
100
+
101
+ 26
102
+ 00:01:00,000 --> 00:01:04,000
103
+ Now, in the same way, if we talk about this A, B, C here.
104
+
105
+ 27
106
+ 00:01:04,000 --> 00:01:06,000
107
+ We are saying both are parent,
108
+
109
+ 28
110
+ 00:01:06,000 --> 00:01:10,000
111
+ so we have A as parent and B as parent,
112
+
113
+ 29
114
+ 00:01:10,000 --> 00:01:14,000
115
+ and then C becomes a child.
116
+
117
+ 30
118
+ 00:01:14,000 --> 00:01:17,000
119
+ So C is from A and B, both.
120
+
121
+ 31
122
+ 00:01:17,000 --> 00:01:19,000
123
+ Now is it possible in Java?
124
+
125
+ 32
126
+ 00:01:19,000 --> 00:01:20,000
127
+ Let's try.
128
+
129
+ 33
130
+ 00:01:20,000 --> 00:01:22,000
131
+ In fact, it is possible in other language like C++.
132
+
133
+ 34
134
+ 00:01:22,000 --> 00:01:24,000
135
+ Let's try in Java.
136
+
137
+ 35
138
+ 00:01:24,000 --> 00:01:26,000
139
+ What I will do is I will just go back to the same class,
140
+
141
+ 36
142
+ 00:01:26,000 --> 00:01:28,000
143
+ okay, same file, demo.
144
+
145
+ 37
146
+ 00:01:28,000 --> 00:01:30,000
147
+ And here let me get a class called A.
148
+
149
+ 38
150
+ 00:01:30,000 --> 00:01:32,000
151
+ And of course A will have some methods.
152
+
153
+ 39
154
+ 00:01:32,000 --> 00:01:34,000
155
+ This should be capital A
156
+
157
+ 40
158
+ 00:01:34,000 --> 00:01:38,000
159
+ and then class B and class C.
160
+
161
+ 41
162
+ 00:01:38,000 --> 00:01:42,000
163
+ Okay, we have this three classes here, okay?
164
+
165
+ 42
166
+ 00:01:42,000 --> 00:01:46,000
167
+ And let's say, okay, let's try this first.
168
+
169
+ 43
170
+ 00:01:46,000 --> 00:01:51,000
171
+ If B extends from A and C extends from B, okay, this works.
172
+
173
+ 44
174
+ 00:01:54,000 --> 00:01:56,000
175
+ We can see there's no problem here,
176
+
177
+ 45
178
+ 00:01:56,000 --> 00:02:01,000
179
+ but what if I want the C to extends from A and B both.
180
+
181
+ 46
182
+ 00:02:01,000 --> 00:02:04,000
183
+ As you can see, this syntax is not working.
184
+
185
+ 47
186
+ 00:02:04,000 --> 00:02:05,000
187
+ It gives you an error as well.
188
+
189
+ 48
190
+ 00:02:05,000 --> 00:02:09,000
191
+ You can't put a comma when you say extends A comma B, okay?
192
+
193
+ 49
194
+ 00:02:09,000 --> 00:02:12,000
195
+ Does it means we can use extend B?
196
+
197
+ 50
198
+ 00:02:12,000 --> 00:02:13,000
199
+ No, even this will not work.
200
+
201
+ 51
202
+ 00:02:13,000 --> 00:02:16,000
203
+ So it doesn't matter what combination you do,
204
+
205
+ 52
206
+ 00:02:16,000 --> 00:02:20,000
207
+ multiple inheritance in Java will not work.
208
+
209
+ 53
210
+ 00:02:20,000 --> 00:02:20,000
211
+ Yeah.
212
+
213
+ 54
214
+ 00:02:20,000 --> 00:02:21,000
215
+ So this thing will not work.
216
+
217
+ 55
218
+ 00:02:21,000 --> 00:02:24,000
219
+ Multiple inheritance will not work.
220
+
221
+ 56
222
+ 00:02:24,000 --> 00:02:25,000
223
+ But the question is why?
224
+
225
+ 57
226
+ 00:02:25,000 --> 00:02:27,000
227
+ So let's try to understand that here.
228
+
229
+ 58
230
+ 00:02:27,000 --> 00:02:28,000
231
+ Now, let's say if we go back
232
+
233
+ 59
234
+ 00:02:28,000 --> 00:02:30,000
235
+ to this particular example here,
236
+
237
+ 60
238
+ 00:02:30,000 --> 00:02:33,000
239
+ let's say you create object of B, okay?
240
+
241
+ 61
242
+ 00:02:33,000 --> 00:02:36,000
243
+ In this scenario, if you create object of B, let's say obj.
244
+
245
+ 62
246
+ 00:02:36,000 --> 00:02:41,000
247
+ Now, obj can call all the methods of B and A both.
248
+
249
+ 63
250
+ 00:02:41,000 --> 00:02:43,000
251
+ So let's say in B, we have a method called show.
252
+
253
+ 64
254
+ 00:02:43,000 --> 00:02:45,000
255
+ Okay, let's say there's a show method,
256
+
257
+ 65
258
+ 00:02:45,000 --> 00:02:49,000
259
+ and then from obj, you are trying to call show.
260
+
261
+ 66
262
+ 00:02:49,000 --> 00:02:50,000
263
+ Will this work?
264
+
265
+ 67
266
+ 00:02:50,000 --> 00:02:51,000
267
+ Yes, this will work.
268
+
269
+ 68
270
+ 00:02:51,000 --> 00:02:55,000
271
+ Let's say in A, we have a method called abc.
272
+
273
+ 69
274
+ 00:02:55,000 --> 00:02:59,000
275
+ Now, if you try to call obj.abc, yes, this will work,
276
+
277
+ 70
278
+ 00:02:59,000 --> 00:03:02,000
279
+ but what happens, you know when you say obj.abc,
280
+
281
+ 71
282
+ 00:03:02,000 --> 00:03:06,000
283
+ it'll try to search for it first in the B class.
284
+
285
+ 72
286
+ 00:03:06,000 --> 00:03:07,000
287
+ In B class, we don't have it.
288
+
289
+ 73
290
+ 00:03:07,000 --> 00:03:09,000
291
+ So it'll say, okay, I don't have that method.
292
+
293
+ 74
294
+ 00:03:09,000 --> 00:03:11,000
295
+ Maybe my parent class will have,
296
+
297
+ 75
298
+ 00:03:11,000 --> 00:03:13,000
299
+ so it'll go to A by checking,
300
+
301
+ 76
302
+ 00:03:13,000 --> 00:03:14,000
303
+ "Hey, do you have abc?"
304
+
305
+ 77
306
+ 00:03:14,000 --> 00:03:16,000
307
+ Parent will say, "Yes, I have."
308
+
309
+ 78
310
+ 00:03:16,000 --> 00:03:18,000
311
+ Now, in this case it'll work.
312
+
313
+ 79
314
+ 00:03:18,000 --> 00:03:20,000
315
+ The same thing is applicable for C as well.
316
+
317
+ 80
318
+ 00:03:20,000 --> 00:03:23,000
319
+ Let's say if you create object of C, which is obj again.
320
+
321
+ 81
322
+ 00:03:23,000 --> 00:03:26,000
323
+ And then if you try to call a method,
324
+
325
+ 82
326
+ 00:03:26,000 --> 00:03:28,000
327
+ let's say, A has a method called x,
328
+
329
+ 83
330
+ 00:03:28,000 --> 00:03:31,000
331
+ B has a method called y and C has a method called z.
332
+
333
+ 84
334
+ 00:03:31,000 --> 00:03:33,000
335
+ So let's say we have z method.
336
+
337
+ 85
338
+ 00:03:33,000 --> 00:03:35,000
339
+ and then when you try to call z, this will work.
340
+
341
+ 86
342
+ 00:03:35,000 --> 00:03:37,000
343
+ Because in C itself, we have the method.
344
+
345
+ 87
346
+ 00:03:37,000 --> 00:03:42,000
347
+ If you say obj.y, will this work?
348
+
349
+ 88
350
+ 00:03:42,000 --> 00:03:44,000
351
+ Yes, because it is coming from B.
352
+
353
+ 89
354
+ 00:03:44,000 --> 00:03:47,000
355
+ Now, when you say obj.x,
356
+
357
+ 90
358
+ 00:03:47,000 --> 00:03:50,000
359
+ it'll also work because it'll call from A.
360
+
361
+ 91
362
+ 00:03:50,000 --> 00:03:51,000
363
+ So first it'll search in C.
364
+
365
+ 92
366
+ 00:03:51,000 --> 00:03:53,000
367
+ In C, we don't have x, it'll go to B.
368
+
369
+ 93
370
+ 00:03:53,000 --> 00:03:55,000
371
+ In B, also we don't have x.
372
+
373
+ 94
374
+ 00:03:55,000 --> 00:03:58,000
375
+ It'll go to A, yes in A, we have x.
376
+
377
+ 95
378
+ 00:03:58,000 --> 00:04:00,000
379
+ Okay, it works.
380
+
381
+ 96
382
+ 00:04:00,000 --> 00:04:02,000
383
+ But now if you come back to this example,
384
+
385
+ 97
386
+ 00:04:02,000 --> 00:04:04,000
387
+ let's say if you get object of C as obj.
388
+
389
+ 98
390
+ 00:04:04,000 --> 00:04:07,000
391
+ So let's say this is C object, okay?
392
+
393
+ 99
394
+ 00:04:07,000 --> 00:04:10,000
395
+ And then let's say in this A,
396
+
397
+ 100
398
+ 00:04:10,000 --> 00:04:12,000
399
+ we have a method called show, okay?
400
+
401
+ 101
402
+ 00:04:12,000 --> 00:04:14,000
403
+ And that's how we're working.
404
+
405
+ 102
406
+ 00:04:14,000 --> 00:04:17,000
407
+ So let's say if you call show now,
408
+
409
+ 103
410
+ 00:04:17,000 --> 00:04:20,000
411
+ now of course C will say, "Okay, I don't have a method show.
412
+
413
+ 104
414
+ 00:04:20,000 --> 00:04:22,000
415
+ Will this work? Let me ask my parent."
416
+
417
+ 105
418
+ 00:04:22,000 --> 00:04:23,000
419
+ So it'll go to A,
420
+
421
+ 106
422
+ 00:04:23,000 --> 00:04:26,000
423
+ A will say, "Okay, I have show, problem solved."
424
+
425
+ 107
426
+ 00:04:26,000 --> 00:04:27,000
427
+ This will work, right?
428
+
429
+ 108
430
+ 00:04:27,000 --> 00:04:28,000
431
+ In general, I'm not talking about Java.
432
+
433
+ 109
434
+ 00:04:28,000 --> 00:04:30,000
435
+ Let's say in general, this is how it works.
436
+
437
+ 110
438
+ 00:04:30,000 --> 00:04:34,000
439
+ Now, let's say we have, in B, we have a method called X.
440
+
441
+ 111
442
+ 00:04:34,000 --> 00:04:35,000
443
+ Okay?
444
+
445
+ 112
446
+ 00:04:35,000 --> 00:04:38,000
447
+ Now it'll say obj.x, will this work?
448
+
449
+ 113
450
+ 00:04:38,000 --> 00:04:39,000
451
+ Now it'll search and C.
452
+
453
+ 114
454
+ 00:04:39,000 --> 00:04:40,000
455
+ In C, we don't have it.
456
+
457
+ 115
458
+ 00:04:40,000 --> 00:04:42,000
459
+ In A, also we don't have it, in B we have it.
460
+
461
+ 116
462
+ 00:04:42,000 --> 00:04:44,000
463
+ So this will also work.
464
+
465
+ 117
466
+ 00:04:44,000 --> 00:04:47,000
467
+ Okay, but what if there's a method called y,
468
+
469
+ 118
470
+ 00:04:47,000 --> 00:04:51,000
471
+ which is there in A and B, both, okay?
472
+
473
+ 119
474
+ 00:04:51,000 --> 00:04:55,000
475
+ And now, if you're trying to say obj.y,
476
+
477
+ 120
478
+ 00:04:55,000 --> 00:04:59,000
479
+ the problem is from C, we don't have it,
480
+
481
+ 121
482
+ 00:04:59,000 --> 00:05:03,000
483
+ and A and B both has this method, which one he will choose?
484
+
485
+ 122
486
+ 00:05:03,000 --> 00:05:05,000
487
+ That's a confusion, right?
488
+
489
+ 123
490
+ 00:05:05,000 --> 00:05:07,000
491
+ It is almost same like let's say if you want
492
+
493
+ 124
494
+ 00:05:07,000 --> 00:05:09,000
495
+ to call someone, your phone is dead,
496
+
497
+ 125
498
+ 00:05:09,000 --> 00:05:11,000
499
+ and then now you want to call.
500
+
501
+ 126
502
+ 00:05:11,000 --> 00:05:12,000
503
+ So you can ask your parents.
504
+
505
+ 127
506
+ 00:05:12,000 --> 00:05:13,000
507
+ And both the parents has a phone,
508
+
509
+ 128
510
+ 00:05:13,000 --> 00:05:15,000
511
+ which phone you will choose?
512
+
513
+ 129
514
+ 00:05:15,000 --> 00:05:18,000
515
+ Now, if you chose your dad's phone,
516
+
517
+ 130
518
+ 00:05:18,000 --> 00:05:19,000
519
+ your mom will feel bad.
520
+
521
+ 131
522
+ 00:05:19,000 --> 00:05:22,000
523
+ If you choose your mom's phone, your dad will feel bad.
524
+
525
+ 132
526
+ 00:05:22,000 --> 00:05:25,000
527
+ Again, I'm just giving an example here.
528
+
529
+ 133
530
+ 00:05:25,000 --> 00:05:26,000
531
+ I'm not saying, it's literally happens,
532
+
533
+ 134
534
+ 00:05:26,000 --> 00:05:27,000
535
+ but, in fact,
536
+
537
+ 135
538
+ 00:05:27,000 --> 00:05:29,000
539
+ they'll be happy that you're not using their phone.
540
+
541
+ 136
542
+ 00:05:29,000 --> 00:05:32,000
543
+ But yeah, that's a confusion we have here right now.
544
+
545
+ 137
546
+ 00:05:32,000 --> 00:05:36,000
547
+ This problem is called ambiguity problem.
548
+
549
+ 138
550
+ 00:05:36,000 --> 00:05:37,000
551
+ Okay?
552
+
553
+ 139
554
+ 00:05:37,000 --> 00:05:38,000
555
+ So ambiguity simply means,
556
+
557
+ 140
558
+ 00:05:38,000 --> 00:05:40,000
559
+ we have a confusion here, which one to choose?
560
+
561
+ 141
562
+ 00:05:40,000 --> 00:05:42,000
563
+ Now, this problem is there in multiple languages,
564
+
565
+ 142
566
+ 00:05:42,000 --> 00:05:44,000
567
+ which supports multiple inheritance.
568
+
569
+ 143
570
+ 00:05:44,000 --> 00:05:47,000
571
+ Java says, "Oh, that's a problem?"
572
+
573
+ 144
574
+ 00:05:47,000 --> 00:05:49,000
575
+ Let's remove the future itself.
576
+
577
+ 145
578
+ 00:05:49,000 --> 00:05:50,000
579
+ Okay? I know.
580
+
581
+ 146
582
+ 00:05:50,000 --> 00:05:52,000
583
+ That's a weird way of solving the problem,
584
+
585
+ 147
586
+ 00:05:52,000 --> 00:05:55,000
587
+ but yeah, they have removed the problem itself.
588
+
589
+ 148
590
+ 00:05:55,000 --> 00:05:57,000
591
+ So it's not like they found a solution.
592
+
593
+ 149
594
+ 00:05:57,000 --> 00:05:58,000
595
+ They said,
596
+
597
+ 150
598
+ 00:05:58,000 --> 00:06:00,000
599
+ "Instead of finding a solution, let's remove the feature."
600
+
601
+ 151
602
+ 00:06:00,000 --> 00:06:05,000
603
+ That's right, in Java, multiple inheritance does not work.
604
+
605
+ 152
606
+ 00:06:05,000 --> 00:06:08,000
607
+ Okay, so it's a very famous interview question,
608
+
609
+ 153
610
+ 00:06:08,000 --> 00:06:10,000
611
+ do we support multiple inheritance in Java?
612
+
613
+ 154
614
+ 00:06:10,000 --> 00:06:11,000
615
+ And the answer is no.
616
+
617
+ 155
618
+ 00:06:11,000 --> 00:06:13,000
619
+ There is a internet way,
620
+
621
+ 156
622
+ 00:06:13,000 --> 00:06:15,000
623
+ not actually a way,
624
+
625
+ 157
626
+ 00:06:15,000 --> 00:06:18,000
627
+ just that it is possible by going all through steps.
628
+
629
+ 158
630
+ 00:06:18,000 --> 00:06:21,000
631
+ But yeah, that's how Java is implemented in new feed,
632
+
633
+ 159
634
+ 00:06:21,000 --> 00:06:25,000
635
+ in new versions, they have done something which changes it,
636
+
637
+ 160
638
+ 00:06:25,000 --> 00:06:26,000
639
+ with the help of interfaces
640
+
641
+ 161
642
+ 00:06:26,000 --> 00:06:27,000
643
+ but we don't know interfaces yet.
644
+
645
+ 162
646
+ 00:06:27,000 --> 00:06:32,000
647
+ So, let's say, Java does not support multiple inheritance.
648
+
649
+ 163
650
+ 00:06:33,000 --> 00:06:35,000
651
+ Oh, okay, this makes sense.
652
+
653
+ 164
654
+ 00:06:35,000 --> 00:06:36,000
655
+ See you in the next video.
656
+
02 - Core Java/054 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/055 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/055 This and super method_en.srt ADDED
@@ -0,0 +1,1204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (soft music plays)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:06,000
7
+ -: In this video, let's talk about this and super.
8
+
9
+ 3
10
+ 00:00:06,000 --> 00:00:09,000
11
+ Now this is a very super concept, so let's focus, so
12
+
13
+ 4
14
+ 00:00:09,000 --> 00:00:10,000
15
+ what I'll do is I'll just remove all this thing just
16
+
17
+ 5
18
+ 00:00:10,000 --> 00:00:13,000
19
+ to make it simple and clear this part as well.
20
+
21
+ 6
22
+ 00:00:13,000 --> 00:00:18,000
23
+ And for this, I don't even need this particular classes,
24
+
25
+ 7
26
+ 00:00:18,000 --> 00:00:21,000
27
+ so let me just close these files and keep it simple.
28
+
29
+ 8
30
+ 00:00:21,000 --> 00:00:22,000
31
+ Okay, so we have a very simple code here.
32
+
33
+ 9
34
+ 00:00:22,000 --> 00:00:25,000
35
+ Now what I'll do is just to understand this
36
+
37
+ 10
38
+ 00:00:25,000 --> 00:00:28,000
39
+ and Super, I will create a class called A,
40
+
41
+ 11
42
+ 00:00:28,000 --> 00:00:29,000
43
+ I know this is a very simple name,
44
+
45
+ 12
46
+ 00:00:29,000 --> 00:00:32,000
47
+ but just for the example we can take them
48
+
49
+ 13
50
+ 00:00:32,000 --> 00:00:34,000
51
+ and then we got a class B.
52
+
53
+ 14
54
+ 00:00:34,000 --> 00:00:36,000
55
+ Okay, we got two classes
56
+
57
+ 15
58
+ 00:00:36,000 --> 00:00:41,000
59
+ and then I'm also saying that this B class extends A,
60
+
61
+ 16
62
+ 00:00:41,000 --> 00:00:44,000
63
+ of course we are doing inheritance here and it makes sense
64
+
65
+ 17
66
+ 00:00:44,000 --> 00:00:46,000
67
+ because we just talked about inheritance.
68
+
69
+ 18
70
+ 00:00:46,000 --> 00:00:48,000
71
+ And then what I will do is I will create
72
+
73
+ 19
74
+ 00:00:48,000 --> 00:00:49,000
75
+ a constructor for both.
76
+
77
+ 20
78
+ 00:00:49,000 --> 00:00:51,000
79
+ Of course we can do that, right?
80
+
81
+ 21
82
+ 00:00:51,000 --> 00:00:53,000
83
+ Now before creating a constructor,
84
+
85
+ 22
86
+ 00:00:53,000 --> 00:00:55,000
87
+ let me say if I create object of B,
88
+
89
+ 23
90
+ 00:00:55,000 --> 00:00:57,000
91
+ of course we can do that, right?
92
+
93
+ 24
94
+ 00:00:57,000 --> 00:01:00,000
95
+ So this B class, we got an object of B class here
96
+
97
+ 25
98
+ 00:01:00,000 --> 00:01:01,000
99
+ and we can do that.
100
+
101
+ 26
102
+ 00:01:01,000 --> 00:01:04,000
103
+ Let me create a constructor of B here.
104
+
105
+ 27
106
+ 00:01:04,000 --> 00:01:06,000
107
+ Now how do we create a constructor? It's very simple.
108
+
109
+ 28
110
+ 00:01:06,000 --> 00:01:09,000
111
+ You specify public and then you say B, bracket open,
112
+
113
+ 29
114
+ 00:01:09,000 --> 00:01:13,000
115
+ and then here I will type in B.
116
+
117
+ 30
118
+ 00:01:13,000 --> 00:01:14,000
119
+ I'm just trying to keep it as simple as possible.
120
+
121
+ 31
122
+ 00:01:14,000 --> 00:01:16,000
123
+ That's why we have taken class A and B
124
+
125
+ 32
126
+ 00:01:16,000 --> 00:01:18,000
127
+ and then a very simple statement.
128
+
129
+ 33
130
+ 00:01:18,000 --> 00:01:20,000
131
+ Now what I will do is I will try to compile this code
132
+
133
+ 34
134
+ 00:01:20,000 --> 00:01:22,000
135
+ and you tell me what will be the output.
136
+
137
+ 35
138
+ 00:01:22,000 --> 00:01:23,000
139
+ Compression done, right?
140
+
141
+ 36
142
+ 00:01:23,000 --> 00:01:26,000
143
+ If I run this code, there will be some output. Right?
144
+
145
+ 37
146
+ 00:01:26,000 --> 00:01:28,000
147
+ Now think about this: We are creating the object of B.
148
+
149
+ 38
150
+ 00:01:28,000 --> 00:01:32,000
151
+ We are instantiating it and we have learned about this that
152
+
153
+ 39
154
+ 00:01:32,000 --> 00:01:33,000
155
+ whenever you create the object,
156
+
157
+ 40
158
+ 00:01:33,000 --> 00:01:35,000
159
+ it'll call the constructor of a class.
160
+
161
+ 41
162
+ 00:01:35,000 --> 00:01:37,000
163
+ So the object we are getting is of B,
164
+
165
+ 42
166
+ 00:01:37,000 --> 00:01:40,000
167
+ and we have a constructor, which is B here,
168
+
169
+ 43
170
+ 00:01:40,000 --> 00:01:42,000
171
+ which prints a statement.
172
+
173
+ 44
174
+ 00:01:42,000 --> 00:01:43,000
175
+ So of course I'm expecting
176
+
177
+ 45
178
+ 00:01:43,000 --> 00:01:46,000
179
+ that it'll execute the constructor and it will.
180
+
181
+ 46
182
+ 00:01:46,000 --> 00:01:48,000
183
+ That's what you got in B.
184
+
185
+ 47
186
+ 00:01:48,000 --> 00:01:49,000
187
+ That perfectly makes sense and we have talked
188
+
189
+ 48
190
+ 00:01:49,000 --> 00:01:50,000
191
+ about this from a long time.
192
+
193
+ 49
194
+ 00:01:50,000 --> 00:01:54,000
195
+ The twist here is, what if I have a constructor
196
+
197
+ 50
198
+ 00:01:54,000 --> 00:01:56,000
199
+ in A as well?
200
+
201
+ 51
202
+ 00:01:56,000 --> 00:01:59,000
203
+ And here I'm printing in A.
204
+
205
+ 52
206
+ 00:01:59,000 --> 00:02:01,000
207
+ Now what do you think will be the output?
208
+
209
+ 53
210
+ 00:02:01,000 --> 00:02:05,000
211
+ Because of course we are grading the object of B, not A,
212
+
213
+ 54
214
+ 00:02:05,000 --> 00:02:09,000
215
+ so it should call the constructor of B and that makes sense.
216
+
217
+ 55
218
+ 00:02:09,000 --> 00:02:10,000
219
+ But if you compile this code,
220
+
221
+ 56
222
+ 00:02:10,000 --> 00:02:12,000
223
+ you will see something strange.
224
+
225
+ 57
226
+ 00:02:12,000 --> 00:02:13,000
227
+ If I compile this code
228
+
229
+ 58
230
+ 00:02:13,000 --> 00:02:17,000
231
+ and run, oh, it is also executing the constructor of A.
232
+
233
+ 59
234
+ 00:02:17,000 --> 00:02:19,000
235
+ Now that's weird for us, right?
236
+
237
+ 60
238
+ 00:02:19,000 --> 00:02:22,000
239
+ Because we are creating object of B,
240
+
241
+ 61
242
+ 00:02:22,000 --> 00:02:24,000
243
+ it should only call the construct of B,
244
+
245
+ 62
246
+ 00:02:24,000 --> 00:02:26,000
247
+ but it is also calling the construct of A,
248
+
249
+ 63
250
+ 00:02:26,000 --> 00:02:28,000
251
+ and that sounds weird.
252
+
253
+ 64
254
+ 00:02:28,000 --> 00:02:31,000
255
+ Now we understand that, but at this point, just remember
256
+
257
+ 65
258
+ 00:02:31,000 --> 00:02:32,000
259
+ whenever you get object of a class,
260
+
261
+ 66
262
+ 00:02:32,000 --> 00:02:36,000
263
+ it'll call the constructor of subclass and superclass both.
264
+
265
+ 67
266
+ 00:02:36,000 --> 00:02:39,000
267
+ A is a superclass here, B is subclass.
268
+
269
+ 68
270
+ 00:02:39,000 --> 00:02:41,000
271
+ It'll call the constructor of both.
272
+
273
+ 69
274
+ 00:02:41,000 --> 00:02:43,000
275
+ Why? We'll talk about it in some time,
276
+
277
+ 70
278
+ 00:02:43,000 --> 00:02:45,000
279
+ but it calls the constructor of both.
280
+
281
+ 71
282
+ 00:02:45,000 --> 00:02:46,000
283
+ Now let me just add a twist here,
284
+
285
+ 72
286
+ 00:02:46,000 --> 00:02:50,000
287
+ in B, let me create a parameterize constructor,
288
+
289
+ 73
290
+ 00:02:50,000 --> 00:02:51,000
291
+ and we have seen that, right?
292
+
293
+ 74
294
+ 00:02:51,000 --> 00:02:53,000
295
+ So what is parameterize constructor?
296
+
297
+ 75
298
+ 00:02:53,000 --> 00:02:55,000
299
+ A constructor which takes a value.
300
+
301
+ 76
302
+ 00:02:55,000 --> 00:02:56,000
303
+ Let's say this is N, okay?
304
+
305
+ 77
306
+ 00:02:56,000 --> 00:03:00,000
307
+ And here, I'll print "in B int"
308
+
309
+ 78
310
+ 00:03:00,000 --> 00:03:03,000
311
+ because we have a constructor which takes
312
+
313
+ 79
314
+ 00:03:03,000 --> 00:03:04,000
315
+ a int n parameter.
316
+
317
+ 80
318
+ 00:03:04,000 --> 00:03:07,000
319
+ I'm just printing just int just to differentiate
320
+
321
+ 81
322
+ 00:03:07,000 --> 00:03:08,000
323
+ between these two statements.
324
+
325
+ 82
326
+ 00:03:08,000 --> 00:03:11,000
327
+ Now with this, if I compile this code and run,
328
+
329
+ 83
330
+ 00:03:11,000 --> 00:03:11,000
331
+ what do you think?
332
+
333
+ 84
334
+ 00:03:11,000 --> 00:03:13,000
335
+ What will be the output?
336
+
337
+ 85
338
+ 00:03:13,000 --> 00:03:14,000
339
+ Compile and run.
340
+
341
+ 86
342
+ 00:03:14,000 --> 00:03:16,000
343
+ Still it is in A and in B.
344
+
345
+ 87
346
+ 00:03:16,000 --> 00:03:18,000
347
+ Why not in B int is because
348
+
349
+ 88
350
+ 00:03:18,000 --> 00:03:20,000
351
+ when you are creating the object,
352
+
353
+ 89
354
+ 00:03:20,000 --> 00:03:22,000
355
+ you are not passing any value here.
356
+
357
+ 90
358
+ 00:03:22,000 --> 00:03:25,000
359
+ Basically you are calling a default constructor,
360
+
361
+ 91
362
+ 00:03:25,000 --> 00:03:27,000
363
+ but if you pass a value, let's say five,
364
+
365
+ 92
366
+ 00:03:27,000 --> 00:03:30,000
367
+ in this case you are specifically mentioning, "Hey,
368
+
369
+ 93
370
+ 00:03:30,000 --> 00:03:32,000
371
+ I'm creating an object of B
372
+
373
+ 94
374
+ 00:03:32,000 --> 00:03:34,000
375
+ and I'm passing a integer here,
376
+
377
+ 95
378
+ 00:03:34,000 --> 00:03:38,000
379
+ so it'll call the constructor of B, which takes integer.
380
+
381
+ 96
382
+ 00:03:38,000 --> 00:03:41,000
383
+ Now by doing this, if I run this code,
384
+
385
+ 97
386
+ 00:03:41,000 --> 00:03:43,000
387
+ or you can see it is printing in A
388
+
389
+ 98
390
+ 00:03:43,000 --> 00:03:45,000
391
+ and in B, int.
392
+
393
+ 99
394
+ 00:03:45,000 --> 00:03:47,000
395
+ Okay, that actually makes sense.
396
+
397
+ 100
398
+ 00:03:47,000 --> 00:03:49,000
399
+ It'll call the construct of A,
400
+
401
+ 101
402
+ 00:03:49,000 --> 00:03:53,000
403
+ but what if I also have a parameterize constructor in
404
+
405
+ 102
406
+ 00:03:53,000 --> 00:03:55,000
407
+ A as well, which takes a N
408
+
409
+ 103
410
+ 00:03:55,000 --> 00:03:59,000
411
+ and it also prints in A int.
412
+
413
+ 104
414
+ 00:03:59,000 --> 00:04:02,000
415
+ Now, since we were not having a parameterize constructor,
416
+
417
+ 105
418
+ 00:04:02,000 --> 00:04:03,000
419
+ it was called a (indistinct) constructor.
420
+
421
+ 106
422
+ 00:04:03,000 --> 00:04:05,000
423
+ That's what I'm assuming at this point.
424
+
425
+ 107
426
+ 00:04:05,000 --> 00:04:08,000
427
+ Now, when you have a parameterize constructor for both,
428
+
429
+ 108
430
+ 00:04:08,000 --> 00:04:10,000
431
+ for A and B both,
432
+
433
+ 109
434
+ 00:04:10,000 --> 00:04:12,000
435
+ now there is an expectation
436
+
437
+ 110
438
+ 00:04:12,000 --> 00:04:15,000
439
+ that it'll print in A int and in B int.
440
+
441
+ 111
442
+ 00:04:15,000 --> 00:04:16,000
443
+ And that's what I'm thinking.
444
+
445
+ 112
446
+ 00:04:16,000 --> 00:04:18,000
447
+ I'm not sure what you are thinking.
448
+
449
+ 113
450
+ 00:04:18,000 --> 00:04:20,000
451
+ Let's try, let's see if this works.
452
+
453
+ 114
454
+ 00:04:20,000 --> 00:04:23,000
455
+ Oh no, what is happening here?
456
+
457
+ 115
458
+ 00:04:23,000 --> 00:04:26,000
459
+ It is calling the the parameters constructor of B.
460
+
461
+ 116
462
+ 00:04:26,000 --> 00:04:27,000
463
+ That actually makes sense, but why?
464
+
465
+ 117
466
+ 00:04:27,000 --> 00:04:29,000
467
+ The default construct of A,
468
+
469
+ 118
470
+ 00:04:29,000 --> 00:04:32,000
471
+ it should have been called this one, right?
472
+
473
+ 119
474
+ 00:04:32,000 --> 00:04:34,000
475
+ Let's understand why it is first of all,
476
+
477
+ 120
478
+ 00:04:34,000 --> 00:04:36,000
479
+ calling the constructor of parent class.
480
+
481
+ 121
482
+ 00:04:36,000 --> 00:04:37,000
483
+ Why in the first place?
484
+
485
+ 122
486
+ 00:04:37,000 --> 00:04:40,000
487
+ The thing is, and remember this point,
488
+
489
+ 123
490
+ 00:04:40,000 --> 00:04:45,000
491
+ every constructor in Java has a method which is there,
492
+
493
+ 124
494
+ 00:04:47,000 --> 00:04:49,000
495
+ even if you don't mention, okay?
496
+
497
+ 125
498
+ 00:04:49,000 --> 00:04:52,000
499
+ And that method is super.
500
+
501
+ 126
502
+ 00:04:52,000 --> 00:04:56,000
503
+ Now this method is there, even if you don't mention,
504
+
505
+ 127
506
+ 00:04:56,000 --> 00:04:57,000
507
+ you can imagine that's like a John Cena.
508
+
509
+ 128
510
+ 00:04:57,000 --> 00:04:59,000
511
+ I don't know if you know the John Cena memes.
512
+
513
+ 129
514
+ 00:04:59,000 --> 00:05:02,000
515
+ It's just that you can't see it. Okay?
516
+
517
+ 130
518
+ 00:05:02,000 --> 00:05:03,000
519
+ So super is there. You can't see it.
520
+
521
+ 131
522
+ 00:05:03,000 --> 00:05:06,000
523
+ Even if you don't mention super, it is there.
524
+
525
+ 132
526
+ 00:05:06,000 --> 00:05:08,000
527
+ So by default, every constructor,
528
+
529
+ 133
530
+ 00:05:08,000 --> 00:05:11,000
531
+ the first statement is super
532
+
533
+ 134
534
+ 00:05:11,000 --> 00:05:14,000
535
+ and every constructor not just this one,
536
+
537
+ 135
538
+ 00:05:14,000 --> 00:05:16,000
539
+ every constructor, here as well.
540
+
541
+ 136
542
+ 00:05:16,000 --> 00:05:17,000
543
+ Super, okay?
544
+
545
+ 137
546
+ 00:05:17,000 --> 00:05:20,000
547
+ So every constructor will have super.
548
+
549
+ 138
550
+ 00:05:20,000 --> 00:05:22,000
551
+ Same goes for A as well.
552
+
553
+ 139
554
+ 00:05:22,000 --> 00:05:23,000
555
+ It'll also have super
556
+
557
+ 140
558
+ 00:05:24,000 --> 00:05:26,000
559
+ and super,
560
+
561
+ 141
562
+ 00:05:26,000 --> 00:05:27,000
563
+ irrespective to which class it is.
564
+
565
+ 142
566
+ 00:05:27,000 --> 00:05:29,000
567
+ It'll have this statement super,
568
+
569
+ 143
570
+ 00:05:29,000 --> 00:05:31,000
571
+ even if you don't mention it, is there, okay?
572
+
573
+ 144
574
+ 00:05:31,000 --> 00:05:32,000
575
+ That's a point to remember.
576
+
577
+ 145
578
+ 00:05:32,000 --> 00:05:35,000
579
+ Now let's try to understand how it is working.
580
+
581
+ 146
582
+ 00:05:35,000 --> 00:05:36,000
583
+ Let's do a dry run.
584
+
585
+ 147
586
+ 00:05:36,000 --> 00:05:39,000
587
+ The moment you execute this statement, what is happening?
588
+
589
+ 148
590
+ 00:05:39,000 --> 00:05:43,000
591
+ It is calling the constructor of B, which is parametrized.
592
+
593
+ 149
594
+ 00:05:43,000 --> 00:05:46,000
595
+ So it is calling this program method.
596
+
597
+ 150
598
+ 00:05:46,000 --> 00:05:47,000
599
+ So when you execute this method,
600
+
601
+ 151
602
+ 00:05:47,000 --> 00:05:52,000
603
+ the first thing it sees is super, not the system.println
604
+
605
+ 152
606
+ 00:05:52,000 --> 00:05:54,000
607
+ What it is saying is super. Now what is super?
608
+
609
+ 153
610
+ 00:05:54,000 --> 00:05:57,000
611
+ Now super method simply means call the constructor
612
+
613
+ 154
614
+ 00:05:57,000 --> 00:05:59,000
615
+ of a super class.
616
+
617
+ 155
618
+ 00:05:59,000 --> 00:06:00,000
619
+ So let me repeat.
620
+
621
+ 156
622
+ 00:06:00,000 --> 00:06:05,000
623
+ Super means: call the constructor of a super class.
624
+
625
+ 157
626
+ 00:06:05,000 --> 00:06:07,000
627
+ Now what's the in super class?
628
+
629
+ 158
630
+ 00:06:07,000 --> 00:06:10,000
631
+ This is a super class, it is calling the constructor
632
+
633
+ 159
634
+ 00:06:10,000 --> 00:06:12,000
635
+ of a super class, but which one?
636
+
637
+ 160
638
+ 00:06:12,000 --> 00:06:14,000
639
+ The parameterized one.
640
+
641
+ 161
642
+ 00:06:14,000 --> 00:06:18,000
643
+ So the default one, if you can see we are saying default,
644
+
645
+ 162
646
+ 00:06:18,000 --> 00:06:20,000
647
+ we are not passing any parameter here.
648
+
649
+ 163
650
+ 00:06:20,000 --> 00:06:24,000
651
+ So it is calling this particular constructor
652
+
653
+ 164
654
+ 00:06:24,000 --> 00:06:27,000
655
+ and that's why it's printing in A,
656
+
657
+ 165
658
+ 00:06:27,000 --> 00:06:29,000
659
+ and that's why if you can see the output,
660
+
661
+ 166
662
+ 00:06:29,000 --> 00:06:30,000
663
+ it is first printing in A,
664
+
665
+ 167
666
+ 00:06:30,000 --> 00:06:34,000
667
+ and then once it executes the A constructor,
668
+
669
+ 168
670
+ 00:06:34,000 --> 00:06:37,000
671
+ it'll execute the remaining part of B constructor,
672
+
673
+ 169
674
+ 00:06:37,000 --> 00:06:40,000
675
+ which is this part, in B int.
676
+
677
+ 170
678
+ 00:06:40,000 --> 00:06:42,000
679
+ And that's why we got in B int, okay?
680
+
681
+ 171
682
+ 00:06:42,000 --> 00:06:46,000
683
+ That means, if I don't want to call this constructor,
684
+
685
+ 172
686
+ 00:06:46,000 --> 00:06:49,000
687
+ if I want to call the parameterized one, we have
688
+
689
+ 173
690
+ 00:06:49,000 --> 00:06:51,000
691
+ to do only one change, which is
692
+
693
+ 174
694
+ 00:06:51,000 --> 00:06:55,000
695
+ what if in this super you pass a number?
696
+
697
+ 175
698
+ 00:06:55,000 --> 00:06:57,000
699
+ So any is a value, right? It'll have a value,
700
+
701
+ 176
702
+ 00:06:57,000 --> 00:07:00,000
703
+ the same value you are passing to this super.
704
+
705
+ 177
706
+ 00:07:00,000 --> 00:07:02,000
707
+ Now what we are saying is, "Hey Java, I know
708
+
709
+ 178
710
+ 00:07:02,000 --> 00:07:05,000
711
+ you are going to execute this super class constructor,
712
+
713
+ 179
714
+ 00:07:05,000 --> 00:07:06,000
715
+ but I'm passing a parameter there."
716
+
717
+ 180
718
+ 00:07:06,000 --> 00:07:08,000
719
+ So now this time you have to call
720
+
721
+ 181
722
+ 00:07:08,000 --> 00:07:10,000
723
+ the parameterized constructor.
724
+
725
+ 182
726
+ 00:07:10,000 --> 00:07:13,000
727
+ By doing those changes, let's compile and run.
728
+
729
+ 183
730
+ 00:07:13,000 --> 00:07:14,000
731
+ Here we go.
732
+
733
+ 184
734
+ 00:07:14,000 --> 00:07:17,000
735
+ It is printing in A int and in B int.
736
+
737
+ 185
738
+ 00:07:17,000 --> 00:07:20,000
739
+ So super is a very handy tool. It's there already.
740
+
741
+ 186
742
+ 00:07:20,000 --> 00:07:21,000
743
+ You don't have to mention that,
744
+
745
+ 187
746
+ 00:07:21,000 --> 00:07:23,000
747
+ but if you want to make some changes, of course you will
748
+
749
+ 188
750
+ 00:07:23,000 --> 00:07:24,000
751
+ but you have to mention.
752
+
753
+ 189
754
+ 00:07:24,000 --> 00:07:26,000
755
+ So if you want to pass a parametrized constructor,
756
+
757
+ 190
758
+ 00:07:26,000 --> 00:07:30,000
759
+ then explicitly you have to mention super.
760
+
761
+ 191
762
+ 00:07:30,000 --> 00:07:33,000
763
+ I hope that made some sense. Okay?
764
+
765
+ 192
766
+ 00:07:33,000 --> 00:07:35,000
767
+ Now what I want is, I want to call
768
+
769
+ 193
770
+ 00:07:35,000 --> 00:07:38,000
771
+ the default constructor of B.
772
+
773
+ 194
774
+ 00:07:38,000 --> 00:07:40,000
775
+ Okay? I'm not passing any parameter here.
776
+
777
+ 195
778
+ 00:07:40,000 --> 00:07:42,000
779
+ I'm calling a object of B.
780
+
781
+ 196
782
+ 00:07:42,000 --> 00:07:46,000
783
+ So of course if I execute this, if I compile and run,
784
+
785
+ 197
786
+ 00:07:46,000 --> 00:07:49,000
787
+ you can see it's printing in A and in B.
788
+
789
+ 198
790
+ 00:07:49,000 --> 00:07:50,000
791
+ Why?
792
+
793
+ 199
794
+ 00:07:50,000 --> 00:07:52,000
795
+ It's because when you are calling
796
+
797
+ 200
798
+ 00:07:52,000 --> 00:07:55,000
799
+ the default constructor here in default construct of B,
800
+
801
+ 201
802
+ 00:07:55,000 --> 00:07:56,000
803
+ it'll execute first.
804
+
805
+ 202
806
+ 00:07:56,000 --> 00:07:58,000
807
+ It is calling this super,
808
+
809
+ 203
810
+ 00:07:58,000 --> 00:08:00,000
811
+ that means it is calling this part constructor,
812
+
813
+ 204
814
+ 00:08:00,000 --> 00:08:05,000
815
+ which is printing in A, and then it is printing in B.
816
+
817
+ 205
818
+ 00:08:05,000 --> 00:08:08,000
819
+ It'll continue with this execution of B, right?
820
+
821
+ 206
822
+ 00:08:08,000 --> 00:08:11,000
823
+ But what I want now is I know you got the point,
824
+
825
+ 207
826
+ 00:08:11,000 --> 00:08:14,000
827
+ what I want is I want to execute in A int
828
+
829
+ 208
830
+ 00:08:14,000 --> 00:08:18,000
831
+ and then I want to print in B.
832
+
833
+ 209
834
+ 00:08:18,000 --> 00:08:21,000
835
+ So the output which I want is, in A INT in B.
836
+
837
+ 210
838
+ 00:08:21,000 --> 00:08:23,000
839
+ So how can we play with that?
840
+
841
+ 211
842
+ 00:08:23,000 --> 00:08:26,000
843
+ So what if here, if I pass a value at say five
844
+
845
+ 212
846
+ 00:08:26,000 --> 00:08:27,000
847
+ or any number, doesn't matter.
848
+
849
+ 213
850
+ 00:08:27,000 --> 00:08:30,000
851
+ If I pass a number, it'll try to create object of B
852
+
853
+ 214
854
+ 00:08:30,000 --> 00:08:31,000
855
+ with a default constructor,
856
+
857
+ 215
858
+ 00:08:31,000 --> 00:08:33,000
859
+ it'll execute a default constructor.
860
+
861
+ 216
862
+ 00:08:33,000 --> 00:08:36,000
863
+ But now we are calling a super class constructor
864
+
865
+ 217
866
+ 00:08:36,000 --> 00:08:38,000
867
+ by passing a value.
868
+
869
+ 218
870
+ 00:08:38,000 --> 00:08:41,000
871
+ So which constructor will be called?
872
+
873
+ 219
874
+ 00:08:41,000 --> 00:08:46,000
875
+ Of course the second one and it'll print in A int in B.
876
+
877
+ 220
878
+ 00:08:46,000 --> 00:08:49,000
879
+ Let's try, compile, run.
880
+
881
+ 221
882
+ 00:08:49,000 --> 00:08:50,000
883
+ And that's what we got.
884
+
885
+ 222
886
+ 00:08:50,000 --> 00:08:54,000
887
+ So that's how we can play with super and that is fun. Right?
888
+
889
+ 223
890
+ 00:08:54,000 --> 00:08:55,000
891
+ Now I have a question for you.
892
+
893
+ 224
894
+ 00:08:55,000 --> 00:08:57,000
895
+ Maybe you have observed it or not.
896
+
897
+ 225
898
+ 00:08:57,000 --> 00:08:59,000
899
+ See in B class, when we are saying super,
900
+
901
+ 226
902
+ 00:08:59,000 --> 00:09:02,000
903
+ it actually makes sense because we have a super class for B.
904
+
905
+ 227
906
+ 00:09:02,000 --> 00:09:05,000
907
+ Okay? This is A here is a super class.
908
+
909
+ 228
910
+ 00:09:05,000 --> 00:09:08,000
911
+ But when you say super for A, what is a super class for A?
912
+
913
+ 229
914
+ 00:09:08,000 --> 00:09:10,000
915
+ We have not mentioned anything here, right?
916
+
917
+ 230
918
+ 00:09:10,000 --> 00:09:12,000
919
+ Okay, now that's why we have to introduce
920
+
921
+ 231
922
+ 00:09:12,000 --> 00:09:13,000
923
+ a new concept here.
924
+
925
+ 232
926
+ 00:09:13,000 --> 00:09:16,000
927
+ Every class in Java, let me repeat.
928
+
929
+ 233
930
+ 00:09:16,000 --> 00:09:21,000
931
+ Every class in Java extends the object class.
932
+
933
+ 234
934
+ 00:09:22,000 --> 00:09:27,000
935
+ So object is a class in Java, which has a lot of methods.
936
+
937
+ 235
938
+ 00:09:27,000 --> 00:09:28,000
939
+ We'll talk about those methods later.
940
+
941
+ 236
942
+ 00:09:28,000 --> 00:09:32,000
943
+ But every class in Java extends this class.
944
+
945
+ 237
946
+ 00:09:32,000 --> 00:09:34,000
947
+ Even if you don't mention, so even
948
+
949
+ 238
950
+ 00:09:34,000 --> 00:09:36,000
951
+ if you don't mention this, it is extending it.
952
+
953
+ 239
954
+ 00:09:36,000 --> 00:09:39,000
955
+ Again, you can imagine this as a John Cena,
956
+
957
+ 240
958
+ 00:09:39,000 --> 00:09:40,000
959
+ it's there, you can't see it.
960
+
961
+ 241
962
+ 00:09:40,000 --> 00:09:43,000
963
+ Okay? So even if you don't mention, or you mention,
964
+
965
+ 242
966
+ 00:09:43,000 --> 00:09:44,000
967
+ it's the same thing.
968
+
969
+ 243
970
+ 00:09:44,000 --> 00:09:46,000
971
+ So when you say super here,
972
+
973
+ 244
974
+ 00:09:46,000 --> 00:09:50,000
975
+ you're basically calling a constructor of the object class.
976
+
977
+ 245
978
+ 00:09:50,000 --> 00:09:53,000
979
+ Okay? In object class, also we have a constructor.
980
+
981
+ 246
982
+ 00:09:53,000 --> 00:09:56,000
983
+ This is what you are calling, cool, right?
984
+
985
+ 247
986
+ 00:09:56,000 --> 00:09:58,000
987
+ So even if you don't mention it, it's there.
988
+
989
+ 248
990
+ 00:09:58,000 --> 00:10:01,000
991
+ Now you might be thinking the B class must be
992
+
993
+ 249
994
+ 00:10:01,000 --> 00:10:02,000
995
+ extending A and object both?
996
+
997
+ 250
998
+ 00:10:02,000 --> 00:10:06,000
999
+ No, B class extends A, A class extends objects.
1000
+
1001
+ 251
1002
+ 00:10:06,000 --> 00:10:08,000
1003
+ So this is multi-level inheritance, okay?
1004
+
1005
+ 252
1006
+ 00:10:08,000 --> 00:10:10,000
1007
+ There's no multiples till now, okay?
1008
+
1009
+ 253
1010
+ 00:10:10,000 --> 00:10:13,000
1011
+ So yeah, that's how it works. We have object class.
1012
+
1013
+ 254
1014
+ 00:10:13,000 --> 00:10:16,000
1015
+ So this super represents the constructor
1016
+
1017
+ 255
1018
+ 00:10:16,000 --> 00:10:17,000
1019
+ of the object class.
1020
+
1021
+ 256
1022
+ 00:10:17,000 --> 00:10:20,000
1023
+ So we have talked about super, but what is this?
1024
+
1025
+ 257
1026
+ 00:10:20,000 --> 00:10:22,000
1027
+ Okay, now let me introduce this here.
1028
+
1029
+ 258
1030
+ 00:10:22,000 --> 00:10:25,000
1031
+ The output, which I want now is, I want to execute
1032
+
1033
+ 259
1034
+ 00:10:25,000 --> 00:10:28,000
1035
+ both the constructor of B.
1036
+
1037
+ 260
1038
+ 00:10:28,000 --> 00:10:29,000
1039
+ Okay? So let me just keep it default now,
1040
+
1041
+ 261
1042
+ 00:10:29,000 --> 00:10:30,000
1043
+ let me say super,
1044
+
1045
+ 262
1046
+ 00:10:30,000 --> 00:10:33,000
1047
+ I want to execute both the constructor of B.
1048
+
1049
+ 263
1050
+ 00:10:33,000 --> 00:10:35,000
1051
+ So I want only one object, okay?
1052
+
1053
+ 264
1054
+ 00:10:35,000 --> 00:10:38,000
1055
+ With one object, can I execute both the constructor?
1056
+
1057
+ 265
1058
+ 00:10:38,000 --> 00:10:40,000
1059
+ Of course I want to execute the constructor of A,
1060
+
1061
+ 266
1062
+ 00:10:40,000 --> 00:10:44,000
1063
+ which is default, but I want to execute the constructor
1064
+
1065
+ 267
1066
+ 00:10:44,000 --> 00:10:46,000
1067
+ of both B.
1068
+
1069
+ 268
1070
+ 00:10:46,000 --> 00:10:50,000
1071
+ So what I'm saying is, I want in A, I want in B
1072
+
1073
+ 269
1074
+ 00:10:50,000 --> 00:10:53,000
1075
+ and in B int, is it possible?
1076
+
1077
+ 270
1078
+ 00:10:53,000 --> 00:10:55,000
1079
+ For that, what we can do is,
1080
+
1081
+ 271
1082
+ 00:10:55,000 --> 00:10:57,000
1083
+ see we are creating the constructor.
1084
+
1085
+ 272
1086
+ 00:10:57,000 --> 00:11:00,000
1087
+ Let me pass a value here, let me pass five.
1088
+
1089
+ 273
1090
+ 00:11:00,000 --> 00:11:01,000
1091
+ So of course by doing that,
1092
+
1093
+ 274
1094
+ 00:11:01,000 --> 00:11:03,000
1095
+ what we are doing is we are calling the constructor,
1096
+
1097
+ 275
1098
+ 00:11:03,000 --> 00:11:06,000
1099
+ which is the parametized one, and we are calling super
1100
+
1101
+ 276
1102
+ 00:11:06,000 --> 00:11:09,000
1103
+ and that's what's calling the super class constructor.
1104
+
1105
+ 277
1106
+ 00:11:09,000 --> 00:11:11,000
1107
+ But then we have one more method called this.
1108
+
1109
+ 278
1110
+ 00:11:11,000 --> 00:11:13,000
1111
+ We have talked about this keyword, right?
1112
+
1113
+ 279
1114
+ 00:11:13,000 --> 00:11:15,000
1115
+ Now, what this will do is,
1116
+
1117
+ 280
1118
+ 00:11:15,000 --> 00:11:18,000
1119
+ this will execute the construct of a same class.
1120
+
1121
+ 281
1122
+ 00:11:18,000 --> 00:11:19,000
1123
+ Let me repeat:
1124
+
1125
+ 282
1126
+ 00:11:19,000 --> 00:11:23,000
1127
+ This will execute the constructor of a same class,
1128
+
1129
+ 283
1130
+ 00:11:23,000 --> 00:11:24,000
1131
+ which is this one.
1132
+
1133
+ 284
1134
+ 00:11:24,000 --> 00:11:26,000
1135
+ We are not passing in a parameter.
1136
+
1137
+ 285
1138
+ 00:11:26,000 --> 00:11:29,000
1139
+ So it'll call the construct of a same class.
1140
+
1141
+ 286
1142
+ 00:11:29,000 --> 00:11:32,000
1143
+ And then this constructor is calling the construct
1144
+
1145
+ 287
1146
+ 00:11:32,000 --> 00:11:32,000
1147
+ of a super class.
1148
+
1149
+ 288
1150
+ 00:11:32,000 --> 00:11:36,000
1151
+ Let's try this works, compile, run.
1152
+
1153
+ 289
1154
+ 00:11:36,000 --> 00:11:40,000
1155
+ And you can see that we got in A, in B, in B int.
1156
+
1157
+ 290
1158
+ 00:11:40,000 --> 00:11:43,000
1159
+ I mean of course this will execute first, this method,
1160
+
1161
+ 291
1162
+ 00:11:43,000 --> 00:11:46,000
1163
+ but this particular method B constructor is
1164
+
1165
+ 292
1166
+ 00:11:46,000 --> 00:11:49,000
1167
+ executing this, which is the default constructor.
1168
+
1169
+ 293
1170
+ 00:11:49,000 --> 00:11:52,000
1171
+ The default constructor executes the super which goes here,
1172
+
1173
+ 294
1174
+ 00:11:52,000 --> 00:11:57,000
1175
+ it'll execute in A, it'll execute in B and then in B int.
1176
+
1177
+ 295
1178
+ 00:11:57,000 --> 00:12:00,000
1179
+ So that's what is, which is this keyword
1180
+
1181
+ 296
1182
+ 00:12:00,000 --> 00:12:02,000
1183
+ and also this method and super method.
1184
+
1185
+ 297
1186
+ 00:12:02,000 --> 00:12:05,000
1187
+ So this method execute the construct of a same class,
1188
+
1189
+ 298
1190
+ 00:12:05,000 --> 00:12:08,000
1191
+ super method executes the construct of a super class.
1192
+
1193
+ 299
1194
+ 00:12:08,000 --> 00:12:09,000
1195
+ So yeah, that's it from this video.
1196
+
1197
+ 300
1198
+ 00:12:09,000 --> 00:12:10,000
1199
+ I hope you enjoyed it.
1200
+
1201
+ 301
1202
+ 00:12:10,000 --> 00:12:13,000
1203
+ Let's see what we can do in the next video.
1204
+
02 - Core Java/056 Method Overriding_en.srt ADDED
@@ -0,0 +1,808 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:02,000
3
+ (bright music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: So once we talked about inheritance
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:07,000
11
+ and method overloading as well, right?
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:08,000
15
+ We have talked about method overloading.
16
+
17
+ 5
18
+ 00:00:08,000 --> 00:00:09,000
19
+ In this video,
20
+
21
+ 6
22
+ 00:00:09,000 --> 00:00:12,000
23
+ let's talk about method overriding. That's right.
24
+
25
+ 7
26
+ 00:00:12,000 --> 00:00:14,000
27
+ So we have two different method,
28
+
29
+ 8
30
+ 00:00:14,000 --> 00:00:16,000
31
+ overloading and method overriding.
32
+
33
+ 9
34
+ 00:00:16,000 --> 00:00:17,000
35
+ So let's talk about overriding here.
36
+
37
+ 10
38
+ 00:00:17,000 --> 00:00:18,000
39
+ So for that, what I will do is
40
+
41
+ 11
42
+ 00:00:18,000 --> 00:00:20,000
43
+ I will just try to keep it simple again
44
+
45
+ 12
46
+ 00:00:20,000 --> 00:00:22,000
47
+ and let's use the class A
48
+
49
+ 13
50
+ 00:00:22,000 --> 00:00:25,000
51
+ and inside this class A, let's say we have a method.
52
+
53
+ 14
54
+ 00:00:25,000 --> 00:00:27,000
55
+ So I will just remove this part.
56
+
57
+ 15
58
+ 00:00:27,000 --> 00:00:31,000
59
+ And here I would say public void show.
60
+
61
+ 16
62
+ 00:00:31,000 --> 00:00:32,000
63
+ Just to keep it simple,
64
+
65
+ 17
66
+ 00:00:32,000 --> 00:00:33,000
67
+ I'm using a very simple example here,
68
+
69
+ 18
70
+ 00:00:33,000 --> 00:00:36,000
71
+ which is show which prints something.
72
+
73
+ 19
74
+ 00:00:36,000 --> 00:00:39,000
75
+ Let's say it prints in show, okay.
76
+
77
+ 20
78
+ 00:00:39,000 --> 00:00:42,000
79
+ Now if you have a method inside a class,
80
+
81
+ 21
82
+ 00:00:42,000 --> 00:00:43,000
83
+ of course you can create the object
84
+
85
+ 22
86
+ 00:00:43,000 --> 00:00:45,000
87
+ and you can call the method, right,
88
+
89
+ 23
90
+ 00:00:45,000 --> 00:00:46,000
91
+ and we have seen that.
92
+
93
+ 24
94
+ 00:00:46,000 --> 00:00:48,000
95
+ So let's say if I go back to my main method,
96
+
97
+ 25
98
+ 00:00:48,000 --> 00:00:51,000
99
+ if I say A obj = new A,
100
+
101
+ 26
102
+ 00:00:51,000 --> 00:00:56,000
103
+ and I can simply say obj.show and it'll work, right.
104
+
105
+ 27
106
+ 00:00:56,000 --> 00:00:57,000
107
+ And it should work.
108
+
109
+ 28
110
+ 00:00:57,000 --> 00:00:59,000
111
+ That's what we have done from a long time.
112
+
113
+ 29
114
+ 00:00:59,000 --> 00:01:02,000
115
+ So let's compile this code and run.
116
+
117
+ 30
118
+ 00:01:02,000 --> 00:01:04,000
119
+ And you can see it prints in show.
120
+
121
+ 31
122
+ 00:01:04,000 --> 00:01:06,000
123
+ Just to keep it simple, we have went
124
+
125
+ 32
126
+ 00:01:06,000 --> 00:01:08,000
127
+ with a very simple example.
128
+
129
+ 33
130
+ 00:01:08,000 --> 00:01:09,000
131
+ Now what I wanna do is
132
+
133
+ 34
134
+ 00:01:09,000 --> 00:01:12,000
135
+ I want to get a class which is class B,
136
+
137
+ 35
138
+ 00:01:12,000 --> 00:01:15,000
139
+ and I want this class B to extends class A.
140
+
141
+ 36
142
+ 00:01:15,000 --> 00:01:18,000
143
+ And of course when you talk about inheritance,
144
+
145
+ 37
146
+ 00:01:18,000 --> 00:01:19,000
147
+ this method of show,
148
+
149
+ 38
150
+ 00:01:19,000 --> 00:01:21,000
151
+ it also will be available inside Class B, right.
152
+
153
+ 39
154
+ 00:01:21,000 --> 00:01:25,000
155
+ So if I create object of class B instead of A,
156
+
157
+ 40
158
+ 00:01:25,000 --> 00:01:28,000
159
+ it'll also work because that's how inheritance works, right.
160
+
161
+ 41
162
+ 00:01:28,000 --> 00:01:31,000
163
+ So if I go back, compile and run, it works.
164
+
165
+ 42
166
+ 00:01:31,000 --> 00:01:33,000
167
+ You can see we got in show.
168
+
169
+ 43
170
+ 00:01:33,000 --> 00:01:37,000
171
+ What I do now is I will also print in A show
172
+
173
+ 44
174
+ 00:01:37,000 --> 00:01:40,000
175
+ just to differentiate that this is getting printed
176
+
177
+ 45
178
+ 00:01:40,000 --> 00:01:41,000
179
+ in the A class, okay.
180
+
181
+ 46
182
+ 00:01:41,000 --> 00:01:43,000
183
+ Now the thing is,
184
+
185
+ 47
186
+ 00:01:43,000 --> 00:01:47,000
187
+ what if you want to have a different definition of it?
188
+
189
+ 48
190
+ 00:01:47,000 --> 00:01:48,000
191
+ Okay, why do we need different definition?
192
+
193
+ 49
194
+ 00:01:48,000 --> 00:01:52,000
195
+ Let's say we got two methods here, public void config.
196
+
197
+ 50
198
+ 00:01:52,000 --> 00:01:54,000
199
+ So let's say we have this method which is called config.
200
+
201
+ 51
202
+ 00:01:54,000 --> 00:01:55,000
203
+ I don't know what it'll do.
204
+
205
+ 52
206
+ 00:01:55,000 --> 00:01:58,000
207
+ Just to keep it simple, I will just say S out
208
+
209
+ 53
210
+ 00:01:58,000 --> 00:02:01,000
211
+ and I will say this is in a config, okay.
212
+
213
+ 54
214
+ 00:02:01,000 --> 00:02:03,000
215
+ And let's say they have different implementation,
216
+
217
+ 55
218
+ 00:02:03,000 --> 00:02:04,000
219
+ they have different statements.
220
+
221
+ 56
222
+ 00:02:04,000 --> 00:02:06,000
223
+ At this point, we are not focusing on statements.
224
+
225
+ 57
226
+ 00:02:06,000 --> 00:02:08,000
227
+ We are here to understand the concept, right?
228
+
229
+ 58
230
+ 00:02:08,000 --> 00:02:10,000
231
+ So let's say it does something,
232
+
233
+ 59
234
+ 00:02:10,000 --> 00:02:12,000
235
+ so method and config does something
236
+
237
+ 60
238
+ 00:02:12,000 --> 00:02:15,000
239
+ and I can actually call both the methods, not just one.
240
+
241
+ 61
242
+ 00:02:15,000 --> 00:02:17,000
243
+ I can call config as well, okay?
244
+
245
+ 62
246
+ 00:02:17,000 --> 00:02:21,000
247
+ And if I compile and run this code, it works.
248
+
249
+ 63
250
+ 00:02:21,000 --> 00:02:24,000
251
+ You can see it says in A show in A config.
252
+
253
+ 64
254
+ 00:02:24,000 --> 00:02:28,000
255
+ Now, let's say I want a different definition for show, okay,
256
+
257
+ 65
258
+ 00:02:28,000 --> 00:02:29,000
259
+ not for config.
260
+
261
+ 66
262
+ 00:02:29,000 --> 00:02:32,000
263
+ So basically what I want is when it comes to B,
264
+
265
+ 67
266
+ 00:02:32,000 --> 00:02:36,000
267
+ and when I call show, it should print in B show.
268
+
269
+ 68
270
+ 00:02:36,000 --> 00:02:39,000
271
+ How do I do that? How do I change the execution?
272
+
273
+ 69
274
+ 00:02:39,000 --> 00:02:41,000
275
+ So what I want is when I call show,
276
+
277
+ 70
278
+ 00:02:41,000 --> 00:02:43,000
279
+ it should not call the show of A
280
+
281
+ 71
282
+ 00:02:43,000 --> 00:02:46,000
283
+ because show of A will print in A show.
284
+
285
+ 72
286
+ 00:02:46,000 --> 00:02:47,000
287
+ I want to use config as it is.
288
+
289
+ 73
290
+ 00:02:47,000 --> 00:02:49,000
291
+ So I can't even remove this inheritance.
292
+
293
+ 74
294
+ 00:02:49,000 --> 00:02:52,000
295
+ If I remove this, and if I define the methods,
296
+
297
+ 75
298
+ 00:02:52,000 --> 00:02:53,000
299
+ of course I can define show,
300
+
301
+ 76
302
+ 00:02:53,000 --> 00:02:57,000
303
+ but then I want this config to be coming from A.
304
+
305
+ 77
306
+ 00:02:57,000 --> 00:02:58,000
307
+ So of course you have to keep it.
308
+
309
+ 78
310
+ 00:02:58,000 --> 00:03:02,000
311
+ You have to say Class B extends A, because we want config.
312
+
313
+ 79
314
+ 00:03:02,000 --> 00:03:05,000
315
+ What we don't want of A is show
316
+
317
+ 80
318
+ 00:03:05,000 --> 00:03:07,000
319
+ because it is printing in A show.
320
+
321
+ 81
322
+ 00:03:07,000 --> 00:03:08,000
323
+ I wanna do something else.
324
+
325
+ 82
326
+ 00:03:08,000 --> 00:03:11,000
327
+ In that scenario, you can say public void show,
328
+
329
+ 83
330
+ 00:03:11,000 --> 00:03:13,000
331
+ you can write the same method name
332
+
333
+ 84
334
+ 00:03:13,000 --> 00:03:14,000
335
+ or maybe a different name.
336
+
337
+ 85
338
+ 00:03:14,000 --> 00:03:17,000
339
+ You can say in show1, I mean show1
340
+
341
+ 86
342
+ 00:03:17,000 --> 00:03:21,000
343
+ and you can print here in B show.
344
+
345
+ 87
346
+ 00:03:21,000 --> 00:03:22,000
347
+ I mean of course you can do this.
348
+
349
+ 88
350
+ 00:03:22,000 --> 00:03:24,000
351
+ The only thing is
352
+
353
+ 89
354
+ 00:03:24,000 --> 00:03:26,000
355
+ if you execute this code now,
356
+
357
+ 90
358
+ 00:03:26,000 --> 00:03:28,000
359
+ it'll still print in A show.
360
+
361
+ 91
362
+ 00:03:28,000 --> 00:03:30,000
363
+ You know why? is because we are calling show,
364
+
365
+ 92
366
+ 00:03:30,000 --> 00:03:32,000
367
+ and both these methods are different.
368
+
369
+ 93
370
+ 00:03:32,000 --> 00:03:36,000
371
+ One with name show and one with name show1, okay.
372
+
373
+ 94
374
+ 00:03:36,000 --> 00:03:37,000
375
+ That means if I call show1, then it'll work,
376
+
377
+ 95
378
+ 00:03:37,000 --> 00:03:40,000
379
+ then it'll print in B show.
380
+
381
+ 96
382
+ 00:03:40,000 --> 00:03:41,000
383
+ But what I want is
384
+
385
+ 97
386
+ 00:03:41,000 --> 00:03:43,000
387
+ I want them to have a same name.
388
+
389
+ 98
390
+ 00:03:43,000 --> 00:03:46,000
391
+ I want my this method, which is show
392
+
393
+ 99
394
+ 00:03:46,000 --> 00:03:49,000
395
+ should override the method here.
396
+
397
+ 100
398
+ 00:03:49,000 --> 00:03:50,000
399
+ Is it possible?
400
+
401
+ 101
402
+ 00:03:50,000 --> 00:03:51,000
403
+ And the answer is yes.
404
+
405
+ 102
406
+ 00:03:51,000 --> 00:03:53,000
407
+ In Java we get this amazing feature where
408
+
409
+ 103
410
+ 00:03:53,000 --> 00:03:56,000
411
+ you can basically override the methods
412
+
413
+ 104
414
+ 00:03:56,000 --> 00:03:57,000
415
+ of the patent class.
416
+
417
+ 105
418
+ 00:03:57,000 --> 00:04:02,000
419
+ So of course you want everything except this part. Okay.
420
+
421
+ 106
422
+ 00:04:02,000 --> 00:04:03,000
423
+ I mean, except this show method.
424
+
425
+ 107
426
+ 00:04:03,000 --> 00:04:05,000
427
+ I want config, but I don't want show.
428
+
429
+ 108
430
+ 00:04:05,000 --> 00:04:06,000
431
+ Now, let me give you one more example here.
432
+
433
+ 109
434
+ 00:04:06,000 --> 00:04:08,000
435
+ Remember when we talked about inheritance,
436
+
437
+ 110
438
+ 00:04:08,000 --> 00:04:09,000
439
+ I have used an example
440
+
441
+ 111
442
+ 00:04:09,000 --> 00:04:12,000
443
+ where I was not having any phone in my 10 standard
444
+
445
+ 112
446
+ 00:04:12,000 --> 00:04:15,000
447
+ and my father had a phone, which is 3310.
448
+
449
+ 113
450
+ 00:04:15,000 --> 00:04:18,000
451
+ Now if you ask me at that point, which phone I have,
452
+
453
+ 114
454
+ 00:04:18,000 --> 00:04:22,000
455
+ I would just say 3310 because that's my father's phone.
456
+
457
+ 115
458
+ 00:04:22,000 --> 00:04:24,000
459
+ But after two years, when I was in my 12 standard,
460
+
461
+ 116
462
+ 00:04:24,000 --> 00:04:25,000
463
+ I got my own phone.
464
+
465
+ 117
466
+ 00:04:25,000 --> 00:04:27,000
467
+ I got Motorola C168.
468
+
469
+ 118
470
+ 00:04:27,000 --> 00:04:29,000
471
+ Again, not a smart phone,
472
+
473
+ 119
474
+ 00:04:29,000 --> 00:04:32,000
475
+ but it was good, it was a very slim phone.
476
+
477
+ 120
478
+ 00:04:32,000 --> 00:04:35,000
479
+ So when now if you ask me which phone I have,
480
+
481
+ 121
482
+ 00:04:35,000 --> 00:04:37,000
483
+ I will say I have Motorola C168.
484
+
485
+ 122
486
+ 00:04:37,000 --> 00:04:40,000
487
+ My father still had 3310.
488
+
489
+ 123
490
+ 00:04:40,000 --> 00:04:41,000
491
+ So here, if you can see,
492
+
493
+ 124
494
+ 00:04:41,000 --> 00:04:43,000
495
+ if someone ask my father,
496
+
497
+ 125
498
+ 00:04:43,000 --> 00:04:45,000
499
+ father will say, I have 3310.
500
+
501
+ 126
502
+ 00:04:45,000 --> 00:04:48,000
503
+ If you ask me, I have a choice of saying 3310,
504
+
505
+ 127
506
+ 00:04:48,000 --> 00:04:52,000
507
+ but I will go for C168, which is my phone, right?
508
+
509
+ 128
510
+ 00:04:52,000 --> 00:04:55,000
511
+ So you always give preference to your own features first.
512
+
513
+ 129
514
+ 00:04:55,000 --> 00:04:58,000
515
+ Example, if you call show here,
516
+
517
+ 130
518
+ 00:04:58,000 --> 00:04:59,000
519
+ it'll execute the method of B
520
+
521
+ 131
522
+ 00:04:59,000 --> 00:05:01,000
523
+ instead of executing the method of A.
524
+
525
+ 132
526
+ 00:05:01,000 --> 00:05:04,000
527
+ So basically this method show
528
+
529
+ 133
530
+ 00:05:04,000 --> 00:05:07,000
531
+ overrides the method of A here.
532
+
533
+ 134
534
+ 00:05:07,000 --> 00:05:10,000
535
+ And we can simply execute, compile, and run.
536
+
537
+ 135
538
+ 00:05:10,000 --> 00:05:12,000
539
+ You can see it prints in B show.
540
+
541
+ 136
542
+ 00:05:12,000 --> 00:05:13,000
543
+ Now this will make much more sense
544
+
545
+ 137
546
+ 00:05:13,000 --> 00:05:16,000
547
+ when we say we are creating not A,
548
+
549
+ 138
550
+ 00:05:16,000 --> 00:05:18,000
551
+ but we are creating a calculator
552
+
553
+ 139
554
+ 00:05:18,000 --> 00:05:20,000
555
+ which has a method called let's say,
556
+
557
+ 140
558
+ 00:05:20,000 --> 00:05:22,000
559
+ let me remove config for some time.
560
+
561
+ 141
562
+ 00:05:22,000 --> 00:05:25,000
563
+ Let's say that we have a method called add,
564
+
565
+ 142
566
+ 00:05:25,000 --> 00:05:28,000
567
+ and this will return a value, okay.
568
+
569
+ 143
570
+ 00:05:28,000 --> 00:05:30,000
571
+ And here, instead of printing this,
572
+
573
+ 144
574
+ 00:05:30,000 --> 00:05:31,000
575
+ I can simply accept two values.
576
+
577
+ 145
578
+ 00:05:31,000 --> 00:05:35,000
579
+ I can say int n1, int n2,
580
+
581
+ 146
582
+ 00:05:35,000 --> 00:05:37,000
583
+ and here we have done this before
584
+
585
+ 147
586
+ 00:05:37,000 --> 00:05:38,000
587
+ and that's why I'm writing this code very fast.
588
+
589
+ 148
590
+ 00:05:38,000 --> 00:05:43,000
591
+ I can say return and n1+n2. Okay.
592
+
593
+ 149
594
+ 00:05:43,000 --> 00:05:46,000
595
+ So if your class, which is instead of saying B,
596
+
597
+ 150
598
+ 00:05:46,000 --> 00:05:50,000
599
+ I can say Advanced Calc, which is extending calc.
600
+
601
+ 151
602
+ 00:05:50,000 --> 00:05:52,000
603
+ It'll also have some features.
604
+
605
+ 152
606
+ 00:05:52,000 --> 00:05:56,000
607
+ But let's say I want to add two numbers,
608
+
609
+ 153
610
+ 00:05:56,000 --> 00:05:57,000
611
+ which will also take int
612
+
613
+ 154
614
+ 00:05:57,000 --> 00:05:59,000
615
+ and it'll have the same parameter, okay,
616
+
617
+ 155
618
+ 00:05:59,000 --> 00:06:01,000
619
+ because in method overloading we have seen
620
+
621
+ 156
622
+ 00:06:01,000 --> 00:06:03,000
623
+ it can have the same method name
624
+
625
+ 157
626
+ 00:06:03,000 --> 00:06:04,000
627
+ but different parameters.
628
+
629
+ 158
630
+ 00:06:04,000 --> 00:06:06,000
631
+ Here in method overriding,
632
+
633
+ 159
634
+ 00:06:06,000 --> 00:06:08,000
635
+ it'll be same name, same parameters as well.
636
+
637
+ 160
638
+ 00:06:08,000 --> 00:06:10,000
639
+ I mean same type of parameters,
640
+
641
+ 161
642
+ 00:06:10,000 --> 00:06:12,000
643
+ not the name, doesn't matter name,
644
+
645
+ 162
646
+ 00:06:12,000 --> 00:06:13,000
647
+ let's say n1, n2
648
+
649
+ 163
650
+ 00:06:13,000 --> 00:06:16,000
651
+ and it'll have the same name, same number of parameters,
652
+
653
+ 164
654
+ 00:06:16,000 --> 00:06:18,000
655
+ same type of parameters,
656
+
657
+ 165
658
+ 00:06:18,000 --> 00:06:19,000
659
+ but it'll have a different behavior.
660
+
661
+ 166
662
+ 00:06:19,000 --> 00:06:20,000
663
+ Let's say n1+n2+1.
664
+
665
+ 167
666
+ 00:06:20,000 --> 00:06:22,000
667
+ I'm just adding extra one there.
668
+
669
+ 168
670
+ 00:06:22,000 --> 00:06:27,000
671
+ So what I want is if I comment this section, okay,
672
+
673
+ 169
674
+ 00:06:27,000 --> 00:06:28,000
675
+ at this point I'm not overriding it,
676
+
677
+ 170
678
+ 00:06:28,000 --> 00:06:31,000
679
+ I just have add method inside calc,
680
+
681
+ 171
682
+ 00:06:31,000 --> 00:06:34,000
683
+ and if I create the object of advanced calculator
684
+
685
+ 172
686
+ 00:06:34,000 --> 00:06:38,000
687
+ by saying Advanced Calculator obj = new Advanced Calculator,
688
+
689
+ 173
690
+ 00:06:38,000 --> 00:06:42,000
691
+ and if I try to call the add method by passing 3 and 4,
692
+
693
+ 174
694
+ 00:06:42,000 --> 00:06:44,000
695
+ of course 3 and 4 is 7.
696
+
697
+ 175
698
+ 00:06:44,000 --> 00:06:46,000
699
+ So if I get this value somewhere,
700
+
701
+ 176
702
+ 00:06:46,000 --> 00:06:48,000
703
+ if I say int r1 =,
704
+
705
+ 177
706
+ 00:06:48,000 --> 00:06:51,000
707
+ and if I print the value for r1,
708
+
709
+ 178
710
+ 00:06:51,000 --> 00:06:53,000
711
+ and again, since we have done this code before,
712
+
713
+ 179
714
+ 00:06:53,000 --> 00:06:55,000
715
+ I'm just typing it fast.
716
+
717
+ 180
718
+ 00:06:55,000 --> 00:06:57,000
719
+ Now, what do you think? What will the output?
720
+
721
+ 181
722
+ 00:06:57,000 --> 00:06:58,000
723
+ I'm passing 3 and 4.
724
+
725
+ 182
726
+ 00:06:58,000 --> 00:07:01,000
727
+ So of course it'll first search for this method add
728
+
729
+ 183
730
+ 00:07:01,000 --> 00:07:03,000
731
+ inside the same class.
732
+
733
+ 184
734
+ 00:07:03,000 --> 00:07:05,000
735
+ Of course, we don't have that method.
736
+
737
+ 185
738
+ 00:07:05,000 --> 00:07:07,000
739
+ So it'll go to the upper class by saying,
740
+
741
+ 186
742
+ 00:07:07,000 --> 00:07:10,000
743
+ Hey, you know calc, you are my parent class,
744
+
745
+ 187
746
+ 00:07:10,000 --> 00:07:14,000
747
+ I'm searching for add with you and yes, it is available.
748
+
749
+ 188
750
+ 00:07:14,000 --> 00:07:17,000
751
+ So basically we can just compile this code and run.
752
+
753
+ 189
754
+ 00:07:17,000 --> 00:07:20,000
755
+ You can see we got 7 and that actually works.
756
+
757
+ 190
758
+ 00:07:20,000 --> 00:07:23,000
759
+ But now I want a different definition for add,
760
+
761
+ 191
762
+ 00:07:23,000 --> 00:07:24,000
763
+ I just want some changes.
764
+
765
+ 192
766
+ 00:07:24,000 --> 00:07:26,000
767
+ Instead of adding those two numbers,
768
+
769
+ 193
770
+ 00:07:26,000 --> 00:07:29,000
771
+ it should also add 1 at the end, okay.
772
+
773
+ 194
774
+ 00:07:29,000 --> 00:07:33,000
775
+ So if I compile this code now and run, it'll print 8.
776
+
777
+ 195
778
+ 00:07:33,000 --> 00:07:37,000
779
+ So this add is overriding the add method of calculator.
780
+
781
+ 196
782
+ 00:07:37,000 --> 00:07:40,000
783
+ Okay, just remove this statement, that's extra.
784
+
785
+ 197
786
+ 00:07:40,000 --> 00:07:44,000
787
+ So this concept is called method overriding.
788
+
789
+ 198
790
+ 00:07:44,000 --> 00:07:47,000
791
+ So this method is overriding the method here.
792
+
793
+ 199
794
+ 00:07:48,000 --> 00:07:50,000
795
+ I hope that makes sense.
796
+
797
+ 200
798
+ 00:07:50,000 --> 00:07:52,000
799
+ So this is method overriding.
800
+
801
+ 201
802
+ 00:07:52,000 --> 00:07:54,000
803
+ In fact, there is one more trick here,
804
+
805
+ 202
806
+ 00:07:54,000 --> 00:07:56,000
807
+ which we'll discuss in the next video.
808
+
02 - Core Java/056 Source-code.url ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [InternetShortcut]
2
+ URL=https://github.com/navinreddy20/Javacode.git
02 - Core Java/057 Packages_en.srt ADDED
@@ -0,0 +1,1252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:03,000
3
+ (soft instrumental music)
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,000
7
+ -: In this video let's talk about packages.
8
+
9
+ 3
10
+ 00:00:05,000 --> 00:00:07,000
11
+ The thing is, whenever you have a file,
12
+
13
+ 4
14
+ 00:00:07,000 --> 00:00:11,000
15
+ it doesn't matter is it music files or documents or code,
16
+
17
+ 5
18
+ 00:00:11,000 --> 00:00:13,000
19
+ we normally put them in a folder, right?
20
+
21
+ 6
22
+ 00:00:13,000 --> 00:00:16,000
23
+ And then we create a folder structure as well.
24
+
25
+ 7
26
+ 00:00:16,000 --> 00:00:19,000
27
+ In fact, I remember in my college days when we used
28
+
29
+ 8
30
+ 00:00:19,000 --> 00:00:20,000
31
+ to store different songs
32
+
33
+ 9
34
+ 00:00:20,000 --> 00:00:22,000
35
+ we used to create different folders.
36
+
37
+ 10
38
+ 00:00:22,000 --> 00:00:26,000
39
+ Like we have a Songs folder, then inside that we have
40
+
41
+ 11
42
+ 00:00:26,000 --> 00:00:30,000
43
+ Rock Songs, DJ Songs, Sad Songs, Romantic Songs.
44
+
45
+ 12
46
+ 00:00:30,000 --> 00:00:33,000
47
+ And in fact in that as well, when you go to Sad Songs
48
+
49
+ 13
50
+ 00:00:33,000 --> 00:00:36,000
51
+ we can have Normal Sad Songs, Ultimate Sad Songs.
52
+
53
+ 14
54
+ 00:00:36,000 --> 00:00:38,000
55
+ Okay, now that's exaggeration, but we do that, right?
56
+
57
+ 15
58
+ 00:00:38,000 --> 00:00:39,000
59
+ We create a structure there.
60
+
61
+ 16
62
+ 00:00:39,000 --> 00:00:42,000
63
+ In the same way, when you talk about Java project
64
+
65
+ 17
66
+ 00:00:42,000 --> 00:00:44,000
67
+ you will not be creating one or two files, right?
68
+
69
+ 18
70
+ 00:00:44,000 --> 00:00:46,000
71
+ It will be having multiple files.
72
+
73
+ 19
74
+ 00:00:46,000 --> 00:00:48,000
75
+ Sometimes your project can have
76
+
77
+ 20
78
+ 00:00:48,000 --> 00:00:51,000
79
+ let's say 200 files, 300 files.
80
+
81
+ 21
82
+ 00:00:51,000 --> 00:00:52,000
83
+ Okay, maybe most of the time
84
+
85
+ 22
86
+ 00:00:52,000 --> 00:00:54,000
87
+ when you have a complex project.
88
+
89
+ 23
90
+ 00:00:54,000 --> 00:00:57,000
91
+ Now, how will you put all these files in one folder?
92
+
93
+ 24
94
+ 00:00:57,000 --> 00:00:59,000
95
+ You can actually, you can put everything in one folder.
96
+
97
+ 25
98
+ 00:00:59,000 --> 00:01:02,000
99
+ Now, if you see our project structure here,
100
+
101
+ 26
102
+ 00:01:02,000 --> 00:01:04,000
103
+ what we did is we have this folder called CODES.
104
+
105
+ 27
106
+ 00:01:04,000 --> 00:01:07,000
107
+ And in this CODES we have all of the files.
108
+
109
+ 28
110
+ 00:01:07,000 --> 00:01:09,000
111
+ In fact, we only have three files now,
112
+
113
+ 29
114
+ 00:01:09,000 --> 00:01:11,000
115
+ but just imagine we have more files.
116
+
117
+ 30
118
+ 00:01:11,000 --> 00:01:13,000
119
+ Imagine if we have 100 files.
120
+
121
+ 31
122
+ 00:01:13,000 --> 00:01:15,000
123
+ It's okay to put them in one folder,
124
+
125
+ 32
126
+ 00:01:15,000 --> 00:01:18,000
127
+ but it's always better if you can create a structure
128
+
129
+ 33
130
+ 00:01:18,000 --> 00:01:21,000
131
+ where you can have few files in one folder
132
+
133
+ 34
134
+ 00:01:21,000 --> 00:01:23,000
135
+ and few files in another folder.
136
+
137
+ 35
138
+ 00:01:23,000 --> 00:01:26,000
139
+ And then you can have a folder inside a folder.
140
+
141
+ 36
142
+ 00:01:26,000 --> 00:01:27,000
143
+ Now, normally this type of pattern
144
+
145
+ 37
146
+ 00:01:27,000 --> 00:01:29,000
147
+ in Java is called packages.
148
+
149
+ 38
150
+ 00:01:29,000 --> 00:01:32,000
151
+ Normally you store files in a package.
152
+
153
+ 39
154
+ 00:01:32,000 --> 00:01:35,000
155
+ So, yeah, that's right, the folder is package here.
156
+
157
+ 40
158
+ 00:01:35,000 --> 00:01:38,000
159
+ And of course one package can be a part of another package
160
+
161
+ 41
162
+ 00:01:38,000 --> 00:01:40,000
163
+ the way you have folders inside a folder.
164
+
165
+ 42
166
+ 00:01:40,000 --> 00:01:42,000
167
+ So, how do we do that here in Java?
168
+
169
+ 43
170
+ 00:01:42,000 --> 00:01:44,000
171
+ So, just to make you understand,
172
+
173
+ 44
174
+ 00:01:44,000 --> 00:01:45,000
175
+ let's say we have these two files,
176
+
177
+ 45
178
+ 00:01:45,000 --> 00:01:47,000
179
+ AdvancedCalculator and Calculator.
180
+
181
+ 46
182
+ 00:01:47,000 --> 00:01:49,000
183
+ Now, these two files are related, right?
184
+
185
+ 47
186
+ 00:01:49,000 --> 00:01:51,000
187
+ They both work for the calculator,
188
+
189
+ 48
190
+ 00:01:51,000 --> 00:01:55,000
191
+ so it is a good idea to put them in one folder.
192
+
193
+ 49
194
+ 00:01:55,000 --> 00:01:56,000
195
+ Now, how will you do that?
196
+
197
+ 50
198
+ 00:01:56,000 --> 00:01:58,000
199
+ You have an option here of creating a new folder.
200
+
201
+ 51
202
+ 00:01:58,000 --> 00:01:59,000
203
+ That's one way.
204
+
205
+ 52
206
+ 00:01:59,000 --> 00:02:01,000
207
+ Or you can, what you can do is you can just come back
208
+
209
+ 53
210
+ 00:02:01,000 --> 00:02:04,000
211
+ on top of your class and say you can create a package.
212
+
213
+ 54
214
+ 00:02:04,000 --> 00:02:06,000
215
+ So, the keyword which you use
216
+
217
+ 55
218
+ 00:02:06,000 --> 00:02:07,000
219
+ to create a package is called package,
220
+
221
+ 56
222
+ 00:02:07,000 --> 00:02:10,000
223
+ and you can put this class in that particular package.
224
+
225
+ 57
226
+ 00:02:10,000 --> 00:02:13,000
227
+ Let's say the package name is tools, right?
228
+
229
+ 58
230
+ 00:02:13,000 --> 00:02:15,000
231
+ So, of course you can create any package name,
232
+
233
+ 59
234
+ 00:02:15,000 --> 00:02:17,000
235
+ but it should have an, it should make some sense.
236
+
237
+ 60
238
+ 00:02:17,000 --> 00:02:21,000
239
+ So, you can see I'm saying that they are tools, okay?
240
+
241
+ 61
242
+ 00:02:21,000 --> 00:02:24,000
243
+ And the thing is you can see we are getting an error.
244
+
245
+ 62
246
+ 00:02:24,000 --> 00:02:26,000
247
+ It says that declared package tools
248
+
249
+ 63
250
+ 00:02:26,000 --> 00:02:29,000
251
+ does not match the expected package.
252
+
253
+ 64
254
+ 00:02:29,000 --> 00:02:33,000
255
+ The thing is you don't have Calc inside the package.
256
+
257
+ 65
258
+ 00:02:33,000 --> 00:02:35,000
259
+ In fact, most of the IDs will give you an option
260
+
261
+ 66
262
+ 00:02:35,000 --> 00:02:39,000
263
+ of directly, if I click on Quick Fix, yeah.
264
+
265
+ 67
266
+ 00:02:39,000 --> 00:02:40,000
267
+ So, you can see most of the IDs,
268
+
269
+ 68
270
+ 00:02:40,000 --> 00:02:42,000
271
+ doesn't matter which ID you're using,
272
+
273
+ 69
274
+ 00:02:42,000 --> 00:02:44,000
275
+ in VS Code we have this option.
276
+
277
+ 70
278
+ 00:02:44,000 --> 00:02:46,000
279
+ In most of the famous ID you will get this option
280
+
281
+ 71
282
+ 00:02:46,000 --> 00:02:50,000
283
+ of doing something, some red symbol or something like that.
284
+
285
+ 72
286
+ 00:02:50,000 --> 00:02:52,000
287
+ Here we have an option of Quick Fix.
288
+
289
+ 73
290
+ 00:02:52,000 --> 00:02:57,000
291
+ If I click on that it says Move Calc.java to package tools.
292
+
293
+ 74
294
+ 00:02:57,000 --> 00:02:59,000
295
+ Okay, that is a good idea.
296
+
297
+ 75
298
+ 00:02:59,000 --> 00:03:00,000
299
+ We can click on this,
300
+
301
+ 76
302
+ 00:03:00,000 --> 00:03:04,000
303
+ and you can see it created a folder called tools.
304
+
305
+ 77
306
+ 00:03:04,000 --> 00:03:07,000
307
+ And now we can actually move this to tools as well.
308
+
309
+ 78
310
+ 00:03:07,000 --> 00:03:09,000
311
+ The only thing is when you do that
312
+
313
+ 79
314
+ 00:03:09,000 --> 00:03:13,000
315
+ and when you go to this particular class, okay,
316
+
317
+ 80
318
+ 00:03:13,000 --> 00:03:14,000
319
+ it has already done the changes.
320
+
321
+ 81
322
+ 00:03:14,000 --> 00:03:16,000
323
+ You can see I have not written this.
324
+
325
+ 82
326
+ 00:03:16,000 --> 00:03:19,000
327
+ It is already there thanks to VS Code and the IDE,
328
+
329
+ 83
330
+ 00:03:20,000 --> 00:03:21,000
331
+ so basically you get this here.
332
+
333
+ 84
334
+ 00:03:21,000 --> 00:03:23,000
335
+ So, it's always a good idea
336
+
337
+ 85
338
+ 00:03:23,000 --> 00:03:25,000
339
+ to put your classes in a package.
340
+
341
+ 86
342
+ 00:03:25,000 --> 00:03:28,000
343
+ You can create a complex structure.
344
+
345
+ 87
346
+ 00:03:28,000 --> 00:03:31,000
347
+ If you want you can create one more folder here.
348
+
349
+ 88
350
+ 00:03:31,000 --> 00:03:35,000
351
+ Let's say we got a folder called database,
352
+
353
+ 89
354
+ 00:03:35,000 --> 00:03:37,000
355
+ or maybe dbconnections or dbclasses,
356
+
357
+ 90
358
+ 00:03:37,000 --> 00:03:39,000
359
+ or maybe you can just simply say db.
360
+
361
+ 91
362
+ 00:03:39,000 --> 00:03:41,000
363
+ Now, this db will have all the database connections.
364
+
365
+ 92
366
+ 00:03:41,000 --> 00:03:44,000
367
+ So, let's say if you want to create some files
368
+
369
+ 93
370
+ 00:03:44,000 --> 00:03:47,000
371
+ which will connect with MySQL, Oracle or,
372
+
373
+ 94
374
+ 00:03:47,000 --> 00:03:48,000
375
+ it does something with database,
376
+
377
+ 95
378
+ 00:03:48,000 --> 00:03:52,000
379
+ so you can put all those classes in database folder, okay?
380
+
381
+ 96
382
+ 00:03:52,000 --> 00:03:55,000
383
+ Now, that's how you create a project structure here, okay?
384
+
385
+ 97
386
+ 00:03:55,000 --> 00:03:57,000
387
+ The only thing is if you want,
388
+
389
+ 98
390
+ 00:03:57,000 --> 00:03:58,000
391
+ if you have this structure here.
392
+
393
+ 99
394
+ 00:03:58,000 --> 00:04:01,000
395
+ Let's say if you have Calc and Demo, AdvancedCalc,
396
+
397
+ 100
398
+ 00:04:01,000 --> 00:04:03,000
399
+ and if you can see both are in a package now.
400
+
401
+ 101
402
+ 00:04:03,000 --> 00:04:07,000
403
+ The only problem we will face is if you go to Demo,
404
+
405
+ 102
406
+ 00:04:07,000 --> 00:04:10,000
407
+ and you can see Demo is not a part of any package.
408
+
409
+ 103
410
+ 00:04:10,000 --> 00:04:13,000
411
+ Normally you put the main class,
412
+
413
+ 104
414
+ 00:04:13,000 --> 00:04:16,000
415
+ so the class which has a main method separately,
416
+
417
+ 105
418
+ 00:04:16,000 --> 00:04:17,000
419
+ outside the package so that you can
420
+
421
+ 106
422
+ 00:04:17,000 --> 00:04:19,000
423
+ easily access other classes.
424
+
425
+ 107
426
+ 00:04:19,000 --> 00:04:21,000
427
+ Okay, when I say easily access other classes can I do that?
428
+
429
+ 108
430
+ 00:04:21,000 --> 00:04:24,000
431
+ Can I create object of Calc here?
432
+
433
+ 109
434
+ 00:04:24,000 --> 00:04:26,000
435
+ So, if I say Calc obj equal to new Calc,
436
+
437
+ 110
438
+ 00:04:26,000 --> 00:04:28,000
439
+ which was working earlier,
440
+
441
+ 111
442
+ 00:04:28,000 --> 00:04:31,000
443
+ if you remember our previous examples.
444
+
445
+ 112
446
+ 00:04:31,000 --> 00:04:32,000
447
+ It's not working now.
448
+
449
+ 113
450
+ 00:04:32,000 --> 00:04:34,000
451
+ You can see it says Calc cannot be resolved.
452
+
453
+ 114
454
+ 00:04:34,000 --> 00:04:35,000
455
+ What's wrong?
456
+
457
+ 115
458
+ 00:04:35,000 --> 00:04:38,000
459
+ The problem is Demo and Calc,
460
+
461
+ 116
462
+ 00:04:38,000 --> 00:04:40,000
463
+ now they are in two different folders.
464
+
465
+ 117
466
+ 00:04:40,000 --> 00:04:42,000
467
+ You can't directly access it.
468
+
469
+ 118
470
+ 00:04:42,000 --> 00:04:44,000
471
+ Okay, so when I say you cannot directly access it
472
+
473
+ 119
474
+ 00:04:44,000 --> 00:04:46,000
475
+ do we have an indirect way?
476
+
477
+ 120
478
+ 00:04:46,000 --> 00:04:48,000
479
+ Yes, we have an indirect way.
480
+
481
+ 121
482
+ 00:04:48,000 --> 00:04:51,000
483
+ So, what you can do is if you see this bubble
484
+
485
+ 122
486
+ 00:04:51,000 --> 00:04:53,000
487
+ it says Import Calc, that's right.
488
+
489
+ 123
490
+ 00:04:53,000 --> 00:04:56,000
491
+ If you want to use Calc in your particular class
492
+
493
+ 124
494
+ 00:04:56,000 --> 00:04:58,000
495
+ you have to say import Calc.
496
+
497
+ 125
498
+ 00:04:58,000 --> 00:05:00,000
499
+ But then Calc belong where?
500
+
501
+ 126
502
+ 00:05:00,000 --> 00:05:03,000
503
+ Calc belongs to tools.Calc.
504
+
505
+ 127
506
+ 00:05:03,000 --> 00:05:05,000
507
+ So, basically you have to mention the package name
508
+
509
+ 128
510
+ 00:05:05,000 --> 00:05:07,000
511
+ and then you have to mention the class name,
512
+
513
+ 129
514
+ 00:05:07,000 --> 00:05:08,000
515
+ whichever you want to import.
516
+
517
+ 130
518
+ 00:05:08,000 --> 00:05:10,000
519
+ And now you can see there's no issue.
520
+
521
+ 131
522
+ 00:05:10,000 --> 00:05:12,000
523
+ How about AdvancedCalculator?
524
+
525
+ 132
526
+ 00:05:12,000 --> 00:05:14,000
527
+ If I want to use AdvancedCalculator,
528
+
529
+ 133
530
+ 00:05:14,000 --> 00:05:17,000
531
+ obj1 is equal to new AdvancedCalculator.
532
+
533
+ 134
534
+ 00:05:17,000 --> 00:05:20,000
535
+ Okay, now you cannot access this one, you know why?
536
+
537
+ 135
538
+ 00:05:20,000 --> 00:05:23,000
539
+ It's because we have only imported Calc,
540
+
541
+ 136
542
+ 00:05:23,000 --> 00:05:25,000
543
+ not AdvancedCalculator.
544
+
545
+ 137
546
+ 00:05:25,000 --> 00:05:26,000
547
+ How will you import this?
548
+
549
+ 138
550
+ 00:05:26,000 --> 00:05:27,000
551
+ You're right.
552
+
553
+ 139
554
+ 00:05:27,000 --> 00:05:30,000
555
+ Just come back here and say import tools.AdvancedCalculator.
556
+
557
+ 140
558
+ 00:05:31,000 --> 00:05:33,000
559
+ So, whichever class you want to use
560
+
561
+ 141
562
+ 00:05:33,000 --> 00:05:35,000
563
+ you can just import them.
564
+
565
+ 142
566
+ 00:05:35,000 --> 00:05:38,000
567
+ In fact, Java internally has a lot of classes.
568
+
569
+ 143
570
+ 00:05:38,000 --> 00:05:39,000
571
+ Example, let's say one of the classes,
572
+
573
+ 144
574
+ 00:05:39,000 --> 00:05:42,000
575
+ which we're going to see in future, which is let's say list.
576
+
577
+ 145
578
+ 00:05:42,000 --> 00:05:46,000
579
+ Now, when we use list, which is inbuilt class,
580
+
581
+ 146
582
+ 00:05:46,000 --> 00:05:47,000
583
+ or inbuilt interface, what is interface?
584
+
585
+ 147
586
+ 00:05:47,000 --> 00:05:48,000
587
+ We'll talk about that later.
588
+
589
+ 148
590
+ 00:05:48,000 --> 00:05:50,000
591
+ Or maybe at this point we can talk about
592
+
593
+ 149
594
+ 00:05:50,000 --> 00:05:53,000
595
+ let's say ArrayList, which is a class.
596
+
597
+ 150
598
+ 00:05:53,000 --> 00:05:56,000
599
+ When we use ArrayList and when you create object of it,
600
+
601
+ 151
602
+ 00:05:56,000 --> 00:05:59,000
603
+ I will say list is equal to new ArrayList.
604
+
605
+ 152
606
+ 00:06:00,000 --> 00:06:01,000
607
+ Now, the moment you do that
608
+
609
+ 153
610
+ 00:06:01,000 --> 00:06:03,000
611
+ it will also come from a package.
612
+
613
+ 154
614
+ 00:06:03,000 --> 00:06:06,000
615
+ You can see it is now given by the IDE,
616
+
617
+ 155
618
+ 00:06:06,000 --> 00:06:08,000
619
+ it is auto-completing it.
620
+
621
+ 156
622
+ 00:06:08,000 --> 00:06:10,000
623
+ But if I remove this line you can see
624
+
625
+ 157
626
+ 00:06:10,000 --> 00:06:10,000
627
+ it will give you error.
628
+
629
+ 158
630
+ 00:06:10,000 --> 00:06:12,000
631
+ It says ArrayList cannot be found.
632
+
633
+ 159
634
+ 00:06:12,000 --> 00:06:14,000
635
+ So, we have to import this one as well,
636
+
637
+ 160
638
+ 00:06:14,000 --> 00:06:16,000
639
+ and this belongs to a package.
640
+
641
+ 161
642
+ 00:06:16,000 --> 00:06:21,000
643
+ Now, that package is import java.util.ArrayList.
644
+
645
+ 162
646
+ 00:06:22,000 --> 00:06:23,000
647
+ This you have to import.
648
+
649
+ 163
650
+ 00:06:23,000 --> 00:06:26,000
651
+ Now, you might be thinking why we have two dots here,
652
+
653
+ 164
654
+ 00:06:26,000 --> 00:06:28,000
655
+ java.util, how it looks like.
656
+
657
+ 165
658
+ 00:06:28,000 --> 00:06:30,000
659
+ So, basically we have a Java folder.
660
+
661
+ 166
662
+ 00:06:30,000 --> 00:06:33,000
663
+ Inside Java folder we have a util folder.
664
+
665
+ 167
666
+ 00:06:33,000 --> 00:06:36,000
667
+ So, it's the folder inside the folder,
668
+
669
+ 168
670
+ 00:06:36,000 --> 00:06:38,000
671
+ and Java has multiple folders if you can see.
672
+
673
+ 169
674
+ 00:06:38,000 --> 00:06:41,000
675
+ Java., we have applet folder,
676
+
677
+ 170
678
+ 00:06:41,000 --> 00:06:46,000
679
+ we have awt folder, beans folder, lang folder, io folder,
680
+
681
+ 171
682
+ 00:06:46,000 --> 00:06:47,000
683
+ and all those things.
684
+
685
+ 172
686
+ 00:06:47,000 --> 00:06:51,000
687
+ So, in general whatever class you use in Java
688
+
689
+ 173
690
+ 00:06:51,000 --> 00:06:53,000
691
+ belongs to a package.
692
+
693
+ 174
694
+ 00:06:53,000 --> 00:06:55,000
695
+ Let me repeat, whichever class,
696
+
697
+ 175
698
+ 00:06:55,000 --> 00:06:59,000
699
+ inbuilt class which you use in Java, belongs to a package.
700
+
701
+ 176
702
+ 00:06:59,000 --> 00:07:02,000
703
+ Now you'll be saying okay, everything makes sense,
704
+
705
+ 177
706
+ 00:07:02,000 --> 00:07:05,000
707
+ but don't you think String is also a class?
708
+
709
+ 178
710
+ 00:07:05,000 --> 00:07:09,000
711
+ And one of our favorite class, which is System.
712
+
713
+ 179
714
+ 00:07:09,000 --> 00:07:11,000
715
+ System is also a class, right?
716
+
717
+ 180
718
+ 00:07:11,000 --> 00:07:14,000
719
+ So, when we are using System we have never imported it.
720
+
721
+ 181
722
+ 00:07:14,000 --> 00:07:16,000
723
+ So, when I say System.out.println,
724
+
725
+ 182
726
+ 00:07:17,000 --> 00:07:19,000
727
+ there was no need to import the package.
728
+
729
+ 183
730
+ 00:07:19,000 --> 00:07:21,000
731
+ But does System belong to a package?
732
+
733
+ 184
734
+ 00:07:21,000 --> 00:07:22,000
735
+ And the answer is yes.
736
+
737
+ 185
738
+ 00:07:22,000 --> 00:07:27,000
739
+ If I go to System and if I go on top here, can you see that?
740
+
741
+ 186
742
+ 00:07:27,000 --> 00:07:28,000
743
+ It says package.
744
+
745
+ 187
746
+ 00:07:28,000 --> 00:07:30,000
747
+ So, this class, System class,
748
+
749
+ 188
750
+ 00:07:30,000 --> 00:07:32,000
751
+ belongs to our package java.lang,
752
+
753
+ 189
754
+ 00:07:32,000 --> 00:07:33,000
755
+ but we never imported it.
756
+
757
+ 190
758
+ 00:07:33,000 --> 00:07:37,000
759
+ The thing is, by default every Java file will have
760
+
761
+ 191
762
+ 00:07:37,000 --> 00:07:40,000
763
+ java.lang by default imported.
764
+
765
+ 192
766
+ 00:07:40,000 --> 00:07:42,000
767
+ So, even if you don't mention that it's there.
768
+
769
+ 193
770
+ 00:07:42,000 --> 00:07:45,000
771
+ This line is there even if you don't mention.
772
+
773
+ 194
774
+ 00:07:45,000 --> 00:07:48,000
775
+ Now, the thing is it's actually this, not this line.
776
+
777
+ 195
778
+ 00:07:48,000 --> 00:07:52,000
779
+ What is by default is this, java.lang.*.
780
+
781
+ 196
782
+ 00:07:52,000 --> 00:07:53,000
783
+ Now, what is this star?
784
+
785
+ 197
786
+ 00:07:53,000 --> 00:07:56,000
787
+ Now, in one particular folder if you have multiple files,
788
+
789
+ 198
790
+ 00:07:56,000 --> 00:08:00,000
791
+ and if you want all the files you can simply say star
792
+
793
+ 199
794
+ 00:08:00,000 --> 00:08:01,000
795
+ just like we have tools here.
796
+
797
+ 200
798
+ 00:08:01,000 --> 00:08:03,000
799
+ In tools we only have two files,
800
+
801
+ 201
802
+ 00:08:03,000 --> 00:08:05,000
803
+ and we are importing both.
804
+
805
+ 202
806
+ 00:08:05,000 --> 00:08:06,000
807
+ So, can we just do that?
808
+
809
+ 203
810
+ 00:08:06,000 --> 00:08:07,000
811
+ Yes, we can.
812
+
813
+ 204
814
+ 00:08:07,000 --> 00:08:10,000
815
+ So, we can simply put a star here, our job is done.
816
+
817
+ 205
818
+ 00:08:10,000 --> 00:08:13,000
819
+ And by doing that I also removed the list.
820
+
821
+ 206
822
+ 00:08:13,000 --> 00:08:15,000
823
+ We don't even need that, you know that.
824
+
825
+ 207
826
+ 00:08:15,000 --> 00:08:17,000
827
+ So, basically if you want to import all the files
828
+
829
+ 208
830
+ 00:08:17,000 --> 00:08:19,000
831
+ you can say star, okay?
832
+
833
+ 209
834
+ 00:08:19,000 --> 00:08:22,000
835
+ So, that's how you can create a package in Java.
836
+
837
+ 210
838
+ 00:08:22,000 --> 00:08:24,000
839
+ As I mentioned, you can create a folder inside a folder.
840
+
841
+ 211
842
+ 00:08:24,000 --> 00:08:27,000
843
+ Example, let's say if I have a folder called other,
844
+
845
+ 212
846
+ 00:08:27,000 --> 00:08:29,000
847
+ so let's say we have other folder.
848
+
849
+ 213
850
+ 00:08:29,000 --> 00:08:32,000
851
+ And this tools actually belongs to other,
852
+
853
+ 214
854
+ 00:08:32,000 --> 00:08:34,000
855
+ so now if I move this you can see
856
+
857
+ 215
858
+ 00:08:34,000 --> 00:08:36,000
859
+ we have tools inside other.
860
+
861
+ 216
862
+ 00:08:36,000 --> 00:08:40,000
863
+ Now, how it will look like when you talk about your Calc,
864
+
865
+ 217
866
+ 00:08:40,000 --> 00:08:43,000
867
+ so you can see it says other.Calc.
868
+
869
+ 218
870
+ 00:08:43,000 --> 00:08:45,000
871
+ So, you have to, if you want to go inside the package,
872
+
873
+ 219
874
+ 00:08:45,000 --> 00:08:48,000
875
+ normally in folder structure we use slash, here we use dot.
876
+
877
+ 220
878
+ 00:08:48,000 --> 00:08:52,000
879
+ So, it is other.tools.Calc, okay?
880
+
881
+ 221
882
+ 00:08:52,000 --> 00:08:54,000
883
+ That's how you have to import it.
884
+
885
+ 222
886
+ 00:08:54,000 --> 00:08:57,000
887
+ And of course you can say star, it will import everything.
888
+
889
+ 223
890
+ 00:08:57,000 --> 00:09:01,000
891
+ Now, my question to you is if I say import other.*,
892
+
893
+ 224
894
+ 00:09:02,000 --> 00:09:07,000
895
+ now is these two line same or can I remove this?
896
+
897
+ 225
898
+ 00:09:07,000 --> 00:09:09,000
899
+ Of course, when you say star it should import everything.
900
+
901
+ 226
902
+ 00:09:09,000 --> 00:09:12,000
903
+ But no, if you can see, it is giving you error.
904
+
905
+ 227
906
+ 00:09:12,000 --> 00:09:15,000
907
+ The reason is when you say other.* it,
908
+
909
+ 228
910
+ 00:09:15,000 --> 00:09:18,000
911
+ so star simply means all the files
912
+
913
+ 229
914
+ 00:09:18,000 --> 00:09:20,000
915
+ not all the folders, okay?
916
+
917
+ 230
918
+ 00:09:20,000 --> 00:09:22,000
919
+ So, in other if you have some files,
920
+
921
+ 231
922
+ 00:09:22,000 --> 00:09:24,000
923
+ let's say if I create a new file here.
924
+
925
+ 232
926
+ 00:09:24,000 --> 00:09:25,000
927
+ I will name this as A.java.
928
+
929
+ 233
930
+ 00:09:25,000 --> 00:09:28,000
931
+ The moment you do that you can see this A class
932
+
933
+ 234
934
+ 00:09:28,000 --> 00:09:29,000
935
+ belongs to other package.
936
+
937
+ 235
938
+ 00:09:29,000 --> 00:09:32,000
939
+ Now you can easily use A but not Calc.
940
+
941
+ 236
942
+ 00:09:32,000 --> 00:09:37,000
943
+ So, if you say A obj2 is equal to new A, this will work.
944
+
945
+ 237
946
+ 00:09:37,000 --> 00:09:40,000
947
+ It's because you are saying other.*,
948
+
949
+ 238
950
+ 00:09:40,000 --> 00:09:41,000
951
+ it will import all the classes,
952
+
953
+ 239
954
+ 00:09:41,000 --> 00:09:44,000
955
+ which are all the files in the other folder,
956
+
957
+ 240
958
+ 00:09:44,000 --> 00:09:46,000
959
+ not inside the folder, which is tools.
960
+
961
+ 241
962
+ 00:09:46,000 --> 00:09:49,000
963
+ So, if you want other, I mean tools as well,
964
+
965
+ 242
966
+ 00:09:49,000 --> 00:09:52,000
967
+ so you have to mention other.tools.*.
968
+
969
+ 243
970
+ 00:09:53,000 --> 00:09:55,000
971
+ So, that's how basically you use a package structure.
972
+
973
+ 244
974
+ 00:09:55,000 --> 00:09:57,000
975
+ Now, there's one thing you know,
976
+
977
+ 245
978
+ 00:09:57,000 --> 00:09:58,000
979
+ not important at this point,
980
+
981
+ 246
982
+ 00:09:58,000 --> 00:10:01,000
983
+ but since we're talking about package let's talk about it
984
+
985
+ 247
986
+ 00:10:01,000 --> 00:10:02,000
987
+ because you will be seeing
988
+
989
+ 248
990
+ 00:10:02,000 --> 00:10:04,000
991
+ those type of structure multiple times.
992
+
993
+ 249
994
+ 00:10:04,000 --> 00:10:06,000
995
+ When you create a project, a big project,
996
+
997
+ 250
998
+ 00:10:06,000 --> 00:10:08,000
999
+ normally you deploy your project
1000
+
1001
+ 251
1002
+ 00:10:08,000 --> 00:10:10,000
1003
+ on the server somewhere, right?
1004
+
1005
+ 252
1006
+ 00:10:10,000 --> 00:10:12,000
1007
+ And maybe you're creating a library, that's right.
1008
+
1009
+ 253
1010
+ 00:10:12,000 --> 00:10:14,000
1011
+ What you do is when you create a project
1012
+
1013
+ 254
1014
+ 00:10:14,000 --> 00:10:17,000
1015
+ it's not always for your use.
1016
+
1017
+ 255
1018
+ 00:10:17,000 --> 00:10:18,000
1019
+ Sometime you create libraries
1020
+
1021
+ 256
1022
+ 00:10:18,000 --> 00:10:20,000
1023
+ so that others can use your files.
1024
+
1025
+ 257
1026
+ 00:10:20,000 --> 00:10:23,000
1027
+ Now, in this case as well you will create a package,
1028
+
1029
+ 258
1030
+ 00:10:23,000 --> 00:10:26,000
1031
+ and then you will give your package to others.
1032
+
1033
+ 259
1034
+ 00:10:26,000 --> 00:10:28,000
1035
+ The only thing is when you are sharing your package
1036
+
1037
+ 260
1038
+ 00:10:28,000 --> 00:10:31,000
1039
+ to the entire world it should be unique,
1040
+
1041
+ 261
1042
+ 00:10:31,000 --> 00:10:32,000
1043
+ it should have a unique name.
1044
+
1045
+ 262
1046
+ 00:10:32,000 --> 00:10:33,000
1047
+ Let me show you something.
1048
+
1049
+ 263
1050
+ 00:10:33,000 --> 00:10:35,000
1051
+ I will go to a website.
1052
+
1053
+ 264
1054
+ 00:10:35,000 --> 00:10:36,000
1055
+ Now, this is one of the website
1056
+
1057
+ 265
1058
+ 00:10:36,000 --> 00:10:39,000
1059
+ where you can get the libraries.
1060
+
1061
+ 266
1062
+ 00:10:39,000 --> 00:10:42,000
1063
+ Now, library simply means if you want to do something,
1064
+
1065
+ 267
1066
+ 00:10:42,000 --> 00:10:45,000
1067
+ and if you don't want to write the code entirely by yourself
1068
+
1069
+ 268
1070
+ 00:10:45,000 --> 00:10:47,000
1071
+ you can use some libraries.
1072
+
1073
+ 269
1074
+ 00:10:47,000 --> 00:10:49,000
1075
+ And most of the time we do that.
1076
+
1077
+ 270
1078
+ 00:10:49,000 --> 00:10:51,000
1079
+ Example, let's say if I want to connect my application
1080
+
1081
+ 271
1082
+ 00:10:51,000 --> 00:10:53,000
1083
+ with MongoDB, which is a database.
1084
+
1085
+ 272
1086
+ 00:10:53,000 --> 00:10:55,000
1087
+ So, I can simply search for mongodb-driver-sync.
1088
+
1089
+ 273
1090
+ 00:10:55,000 --> 00:10:58,000
1091
+ This is a driver which we use to connect Java with MongoDB.
1092
+
1093
+ 274
1094
+ 00:10:58,000 --> 00:11:01,000
1095
+ So, you can use this package in your project.
1096
+
1097
+ 275
1098
+ 00:11:01,000 --> 00:11:03,000
1099
+ Okay, let me select a version.
1100
+
1101
+ 276
1102
+ 00:11:03,000 --> 00:11:07,000
1103
+ So, this is the package, okay?
1104
+
1105
+ 277
1106
+ 00:11:07,000 --> 00:11:10,000
1107
+ Now, the thing is when we talk about this package
1108
+
1109
+ 278
1110
+ 00:11:10,000 --> 00:11:11,000
1111
+ what should be name of it?
1112
+
1113
+ 279
1114
+ 00:11:11,000 --> 00:11:14,000
1115
+ So, this name should be unique on the internet.
1116
+
1117
+ 280
1118
+ 00:11:14,000 --> 00:11:16,000
1119
+ Now, how will you make something unique?
1120
+
1121
+ 281
1122
+ 00:11:16,000 --> 00:11:17,000
1123
+ That's the tricky point, right?
1124
+
1125
+ 282
1126
+ 00:11:17,000 --> 00:11:20,000
1127
+ So, when you are creating a project
1128
+
1129
+ 283
1130
+ 00:11:20,000 --> 00:11:21,000
1131
+ how will you make it unique?
1132
+
1133
+ 284
1134
+ 00:11:21,000 --> 00:11:24,000
1135
+ So, one way to do that is by reversing your domain name.
1136
+
1137
+ 285
1138
+ 00:11:24,000 --> 00:11:24,000
1139
+ That's right.
1140
+
1141
+ 286
1142
+ 00:11:24,000 --> 00:11:26,000
1143
+ Of course, right, when you're building a library
1144
+
1145
+ 287
1146
+ 00:11:26,000 --> 00:11:29,000
1147
+ you will also have your website, your company website maybe.
1148
+
1149
+ 288
1150
+ 00:11:29,000 --> 00:11:31,000
1151
+ So, let's say if we talk about a company like Google.
1152
+
1153
+ 289
1154
+ 00:11:31,000 --> 00:11:34,000
1155
+ So, if I'm working for Google and if I'm creating a library,
1156
+
1157
+ 290
1158
+ 00:11:34,000 --> 00:11:36,000
1159
+ so what I will do is I will name,
1160
+
1161
+ 291
1162
+ 00:11:36,000 --> 00:11:38,000
1163
+ I will say this belongs to a package.
1164
+
1165
+ 292
1166
+ 00:11:38,000 --> 00:11:41,000
1167
+ So, if I'm making a project for let's say Google
1168
+
1169
+ 293
1170
+ 00:11:41,000 --> 00:11:44,000
1171
+ and I'm making a calculator or advanced calculator,
1172
+
1173
+ 294
1174
+ 00:11:44,000 --> 00:11:49,000
1175
+ I will say com.google.calculation.
1176
+
1177
+ 295
1178
+ 00:11:49,000 --> 00:11:50,000
1179
+ Now, this is my package name, okay?
1180
+
1181
+ 296
1182
+ 00:11:50,000 --> 00:11:53,000
1183
+ So, by making com.google I'm making sure
1184
+
1185
+ 297
1186
+ 00:11:53,000 --> 00:11:54,000
1187
+ it is unique, right?
1188
+
1189
+ 298
1190
+ 00:11:54,000 --> 00:11:56,000
1191
+ Only Google can own this domain, right?
1192
+
1193
+ 299
1194
+ 00:11:56,000 --> 00:11:57,000
1195
+ It's their domain.
1196
+
1197
+ 300
1198
+ 00:11:57,000 --> 00:11:58,000
1199
+ So, that's how you do that.
1200
+
1201
+ 301
1202
+ 00:11:58,000 --> 00:12:00,000
1203
+ So, depending upon your project
1204
+
1205
+ 302
1206
+ 00:12:00,000 --> 00:12:01,000
1207
+ you will see these type of packages.
1208
+
1209
+ 303
1210
+ 00:12:01,000 --> 00:12:04,000
1211
+ In fact, in future videos we will be using some packages
1212
+
1213
+ 304
1214
+ 00:12:04,000 --> 00:12:06,000
1215
+ which have com. something.
1216
+
1217
+ 305
1218
+ 00:12:06,000 --> 00:12:08,000
1219
+ It means they have just reverse the domain name
1220
+
1221
+ 306
1222
+ 00:12:08,000 --> 00:12:09,000
1223
+ just to make it unique.
1224
+
1225
+ 307
1226
+ 00:12:09,000 --> 00:12:10,000
1227
+ But again, for learning purpose
1228
+
1229
+ 308
1230
+ 00:12:10,000 --> 00:12:12,000
1231
+ you can name your package anything you want.
1232
+
1233
+ 309
1234
+ 00:12:12,000 --> 00:12:15,000
1235
+ Example, the way we are doing here, package other,
1236
+
1237
+ 310
1238
+ 00:12:15,000 --> 00:12:17,000
1239
+ but it should have a meaning that's important.
1240
+
1241
+ 311
1242
+ 00:12:17,000 --> 00:12:18,000
1243
+ So, yeah, that's about packages.
1244
+
1245
+ 312
1246
+ 00:12:18,000 --> 00:12:20,000
1247
+ Don't worry, we'll use packages more.
1248
+
1249
+ 313
1250
+ 00:12:20,000 --> 00:12:23,000
1251
+ In the upcoming videos it will make much more sense.
1252
+