how to get SET code example
Example 1: java get set
class Employ
{
public String name;
public String getName()
{
return name;
}
public String setName(String newName)
{
this.name = newName;
}
}
Example 2: c# using get set methods
using System;
public class SaleItem
{
public string Name
{ get; set; }
public decimal Price
{ get; set; }
}
class Program
{
static void Main(string[] args)
{
var item = new SaleItem{ Name = "Shoes", Price = 19.95m };
Console.WriteLine($"{item.Name}: sells for {item.Price:C2}");
}
}
Example 3: set get javascript
var person = {
language : "en",
get lang() { return this.language; },
set lang(lang) { this.language = lang; }
};
document.getElementById("demo").innerHTML = person.lang;
person.lang = "es";