0

What are get and set ?

Like getters and setters

4th Apr 2017, 12:19 PM
Tahreem khalil
Tahreem khalil - avatar
5 Respostas
+ 6
it's for encapsulation purpose (data hiding) where sometimes you don't want the data of your object to be modified simply by anyone. You use getter and setter when your variable In the objects are private By using setter method, you can change the objects variable, by calling the method through the object By using getter method, you can get the value of the variable in your object, through calling the method. And the method is the only way to access or alter the variable of the object example: class Car{ private double petrolVolume; public double getPetrolVolume(){ return petrolVolume; } public void setPetrolVolume(double volume){ petrolVolume = volume; } }
4th Apr 2017, 12:30 PM
Heng Jun Xi
Heng Jun Xi - avatar
+ 6
get and set are mostly used in Properties and Indexers. If you make a property like this : public string Name { get; set; } It will automatically make two functions for that property : private Name; public string get_Name() { return Name; } public void set_Name(string value) { Name = value; } Sorry don't know java. The code is in C#.
4th Apr 2017, 12:34 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 5
Well this question is answered. So who ever enters this question, please post on this thread : https://www.sololearn.com/discuss/293240/?ref=app
4th Apr 2017, 1:02 PM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 1
Thank u very much
4th Apr 2017, 12:33 PM
Tahreem khalil
Tahreem khalil - avatar
+ 1
Thanks for the info.
4th Apr 2017, 12:38 PM
Jerry
Jerry - avatar