6.4 OOP Method, Assignment and Builder Part 2
Hello, in this course will continue on the creation of city class it means that we will put the attributes ... and the methods of all classes before we start we must ask a question in what is composed our ... class it means in what is composed a city or if you used a car in what is ... composed a car where what you want to know in the city for example you can know the population, the ... name of the city the surface of the city and all these are attributes that we will use to ... our class so we will start by creating this attribute So private String name does not forget to put the point comma private int population and to finish private float surface you must surely ask a question why we put private we must know that until now you have ... used variables in a method and they are called local variables because they are local where belongs ... to this method only you cannot not access this variable outside of this method you also ... seen with the blocks of code we created in previous videos once you accessed ... you can’t access these variables outside of this block of code but now with the classes ... we can create visible and accessible variables from anywhere within the class we created So this access modifiers will allow us to avoid external elements being able to access our attributes that we ... created so this means that the other classes that can not access our distribution of the city class should know that in the present blow you have mentioned the encapsulation that allows to group data of a ... system here we can take our place city as a system so it will bringing together all of our giving that is-meaning ... attributes and methods But you must surely wonder if the attributes are in private how one can access the attributes inside ... our class to the rescue I won’t go into the whole concept of classes but afterwards it ... will go into the concept of cheerfulness and 7h that will us allow you to modify the attribute or call them so ... afterwards we will see how we will do it So now that we have put the attributes needed for our class we will go back to our Maine class to ... be able to use the object we created the ville01 object that we are going to rename Paris so that it is more reasonable therefore to ... access the methods and attributes that are accessible we must put the name of the object that means Paris ... point and at the same time the point see that we can access several methods and attributes of your class but ... like our class on attributes that are private we can’t access Java automatically insert attributes ... that are inherited from other classes because during the creation of our city class our city class inherited the basic classes of Java so as you can see we can access several ... different methods like the equal method( ) and others and we will try to access our attribute that we have ... created all over the city But to be able to access the attributes we must return to the city class and put for example the name ... private String name we will raise the private and put public and from there we can access from ... our Paris object so returns our class but we will put Paris point So we can see there is the name that appears so we will choose the equal name between quotation marks Paris ... since it is a string Now that I have explained to you how to call our attribution afterwards we will continue with methods but ... it’s exactly the same we’re going to go back to your city class and we’re going to put we’re going to change the audience to ... private and then we’re going to start on the notion of spotter and setter a spotter allows access to our ... our tribe while a setter allows to request a change of status of our attribute With intellji and also other IDE of we can directly manage the lookouts and setteur but we will do it ... us-same so that we can take it in hand and be able to understand the concept of getter and setter so ... start with but before you start if you have red on the name lattribut go back in the hand and you put ... Paris point nom en commentaire So to make the lookout we have to put public String getNon in parentheses then we open the hugs we ... put since we are going to return something we are going to return the name of our city and to ... the inside of our hug we are going to put return non within the time we are going to return the name to end ... no we must always specify it anyway from watchers the name of our method must be watcher more ... the name of the attribute we want to return Now we can return to our class but we will put Paris point there as you see there are ... getNom that is the spotter so we’ll return the name of our city but since we won’t have ... assigned the values to our name we won’t return anything so in the course that will follow we ... will start to give values to assign us is-meaning the name of the city the population and surface ... of the city then soon