So back to our vehicle here as you can see since the brand is 1
read only we cannot update it from inside of our class. But 2
we did that because outside of the class we don't want to be 3
able to do something like this. Honda.brand equal Toyota 4
okay and that's that's working okay we we cannot do it but 5
this is problematic so what you can do instead of using read 6
only you could use the keyword for example private means 7
basically this variable is now completely managed by the class 8
only and cannot be updated or accessed in read or in write 9
outside of the class so now you're going to notice that if 10
I do honda dot, well you cannot see anymore brand it's only 11
private you cannot see it from outside okay so it appear 12
completely from the object but if you're inside your class for 13
example here as you can see I still have brand and speed okay 14
I can access all of that so the private keyword is used when 15
you want to use and manage a variable or function or 16
anything on the inside the class okay but you also have 17
the keyword public okay so by default everything is public so 18
when it's public it means that you can access it from the 19
inside and from the outside so if I go so if I go honda dot as 20
you can see brand is here okay but be careful because 21
something that is public can be updated and that is pretty 22
dangerous okay we want to only be able to update it through 23
set brand so it will be way better to use private on brand 24
now I cannot update brand but set brand is public by default 25
okay I can write it if you want public and this way the only 26
way to update honda is to do a set brand and now I can do 27
something like this. And I can log my brand. Oh obviously I 28
can't okay I cannot read my brand so if you want to read 29
your brand then you will have to create a function that is 30
public for example get brand like this and just return this 31
dot brand like this and so obviously I'm going to say that 32
this is returning a string and instead of doing that, I'm 33
going to do a get brand. And yes it's working so that's the 34
difference between private and public okay private it's only 35
for the class to manage and public anyone can manage it but 36
you also have static I don't know if you know this one so 37
static 38
For example, color, okay, that could be a string as well. So 39
static means that you can use this variable modify it read 40
from it without even having to create an instance of the glass 41
okay so even without having to do a new something and store it 42
somewhere okay so it means that basically I could for example 43
set a default value for my color I don't know black like 44
this and now even if I don't have any vehicle at all I can 45
just do this vehicle dot color and as you can see that's the 46
only one that I can access okay color because it's static and 47
as you can see yeah I can access the color so you don't 48
even need to to create an instance out of it okay so it's 49
sometimes useful for example if you create a function like I I 50
often do when I create an API so for example I create 51
something like this a class for example vehicle API and then 52
inside I'm going to create a static function that is going 53
to be fetch all and then inside I'm going to do an asynchronous 54
request for example. Oh you don't have to write function 55
sorry and well I don't want to have to do something like this 56
anytime I want to use my API you know I don't want to do 57
vehicle API equal new vehicle API etcetera etcetera and then 58
finally do a vehicle API dot fetchAll okay I want to be 59
able to just use my vehicle API like this instantly okay so 60
that's an example of when could use static. Alright so that is 61
pretty much about the accessor so private, public and static. 62
There is another one that is predicted but we will see this 63
one later in the course. All right so see you in the next 64
one. I hope it was clear.