00:00Welcome to this new video about the private access modifier.
00:09This access modifier is used to restrict access to members, attributes, or methods of a class.
00:19Members marked as private or private can only be accessed and modified from their own class, within their own class.
00:29This means that if I have two classes and in one class I have a variable or a method with the private access modifier,
00:42I can't access that method or variable from my other class because it is private only to the class.
00:52So let's look at these examples I have here about the private access modifier.
01:01As you can see we have a class, I have a class car, student, I have a public access modifier class called car,
01:16which contains three private attributes, two of which are of type screen and one of type integer.
01:26We have a parameterized constructor, we have a three-parameter parameterized constructor and as you can see here we have a public method that returns nothing,
01:41but it has, it is parameterized, it has a parameter that is of integer type.
01:50What's going on here?
01:52Here we have an if conditional that tells us if the speed sent to that parameter is greater than zero,
02:07So the speed, the speed attribute is going to be increased by the value, the value that was sent to that method is going to be added to it.
02:27So, we have another class here, Student, which also has three attributes that are private and has its constructor parameterized with its three parameters.
02:44So here we can see that we have access modifiers, the setters and the getters.
02:55The sets are to assign the value to that attribute of this class, but they have something in common, something called validations,
03:11to ensure that what is being entered can be saved in that variable, that is, if it is safe.
03:19And the get methods are to return the information that that variable, or that attribute, contains.
03:31So, over here we can see a test, we create a student object, to which we pass the following parameters,
03:46the name called Ronald, age 43, and average grades.
03:52So when we run this, it should show us,
03:58GetName, means that it will show us his name.
04:07And as we can see, if the program runs correctly,
Sé la primera persona en añadir un comentario