‫Instructor: Hi.
‫Within this lecture we're going to continue deep diving
‫into classes because they're very important as you can see.
‫And we're going to learn about access levels,
‫accessibility levels.
‫Okay.
‫So we have these keywords over here like protected, public.
‫So we didn't pay attention to them very much before,
‫but this time we are gonna learn how they work.
‫So in order to do that,
‫I'm not gonna mess the previous things over here.
‫So I'm gonna create a new Java class.
‫And this time, let's call this something like Simpsons,
‫and we're gonna create some Simpson objects
‫out of this class.
‫So inside of Simpson's class,
‫we're gonna have some similar things
‫like we did in the musician's class.
‫Like we can have a name, we can have an age,
‫we can have a job, right.
‫So let me call this age, job,
‫and maybe you can try with other attributes as well,
‫but I'm gonna keep it simple.
‫I'm gonna say generate constructor, choose everything,
‫and hit okay.
‫So this will be my constructor.
‫As you can see, I have the same setup over here
‫like we did in the musicians.
‫Now let's create an another method called makeSimpsons.
‫Okay.
‫And inside of these methods we are going to make Simpsons.
‫Of course we don't have to do that.
‫I'm just doing this in order to be tidy,
‫in order to be structural.
‫So let me call the first one Homer
‫and then I say new Simpsons.
‫It will ask for a name, ask for an age, and ask for a job.
‫And as much as remember the Homer Simpson
‫was a nuclear safety guy.
‫So I'm going to say nuclear.
‫And over here it really doesn't have any differences
‫when we compare it to the musicians right now.
‫So if you say Homer.age, you can reach the age.
‫And you can even change it.
‫Like you can make it 51.
‫And let me print the age so that we can be certain
‫that we got to change it once we initialize it.
‫Okay.
‫Let me call, makeSimpsons over here
‫so that it will get executed.
‫So let me run the emulator,
‫and of course we will have to track this in our logcat.
‫So here you go.
‫We see that 51.
‫And it means that everything is working
‫as it's supposed to be.
‫But let me add public keyword over here.
‫So what does public mean?
‫It's actually detectable over here
‫because it's public by default.
‫Public means that it can be reached
‫within other classes as well.
‫So we are writing string name in Simpsons,
‫but you can actually change it
‫or read it from other classes like main activity as well.
‫But if I do something like this private, okay,
‫then you will-
‫I would get some errors
‫because age has private property right now
‫so you can initialize it like in Simpson's Homer case,
‫but you cannot reach it and change it afterwards.
‫As you can see, it doesn't even compile it.
‫It says that age has private access in Simpsons.
‫So if you make your attributes private
‫then you cannot change it afterwards.
‫You cannot even read it.
‫Of course, there are other methods
‫like getters and setters in order
‫to have some reading options,
‫but not writeable options.
‫We're gonna look into that later on.
‫So other than public and private,
‫there are some other key words like protected as well.
‫So protected means it's protected
‫and you can reach it from the same class,
‫but when you do it private,
‫you can actually reach it from the same class.
‫But if you do protect it,
‫you can reach it in the same Java file.
‫Okay, so if you have class inside of a class
‫or something like that, then you can reach it
‫once you define it as protected.
‫Once you define it as public,
‫you can reach it from any class.
‫Once you do it as private,
‫then you cannot reach it from anywhere else,
‫but within your same class.
‫So when you first deal with Android development,
‫you don't really actually involve with this decision at all.
‫So it really doesn't matter for you
‫if you make it protected or private or public.
‫But once you get into bigger projects,
‫once you start working, collaborating with other developers
‫then you should really pay attention to those.
‫Because if you don't want them to be public,
‫then don't make it public.
‫But if you want this to work like this,
‫like we have seen before,
‫then you should change it back to the public
‫and make sure you can reach Homer.age
‫or Homer.instrument or Homer.name within another class.
‫Then you should declare it as public.
‫So this is how you work with accessibility levels
‫inside of Android development.
‫So right now we only have one issue to cover
‫inside of classes subject,
‫and that is getters and setters.
‫We're gonna look into that in the next lecture.