{ name = newName; } } JavaScript In this example constructor-function Student is used to create objects representing a student with only the name stored. function Student(name) { var _name = name; this.getName = function() { return _name; }; this.setName = function(value) { _name = value; }; } Or (using a deprecated way to define accessors in Web browsers): function Student(name){ var _name = name; this.__defineGetter__('name', function() { return _name; }); this.__defineSetter__('name', function(value) { _name = value; }); } Or (using prototypes for inheritance and ES6 accessor syntax): function Student(name){ this._name = name; } Student.prototype = { get name() { return this._name; }, set name(value) { this._name = value; } }; Or (without using prototypes): var Student = { get name() { return this._name; }, set name(value) { this._name = value; } }; Or (using defineProperty): function Student(name){ this._name = name; } Object.defineProperty(Student.prototype, 'name', { get: function() { return this._name; }, set: function(value) { this._name = value; } }); ActionScript 3.0 package { public class Student { private var _name : String; public function get name() : String { return _name; } public function set name(value : String) : void { _name = value; } } } Objective-C Using traditional Objective-C 1.0 syntax, with manual reference counting as the one working on GNUstep on Ubuntu 12.04: @interface Student : NSObject { NSString *_name; } - (NSString *)name; - (void)setName:(NSString *)name; @end @implementation Student - (NSString *)name { return _name; } - (void)setName:(NSString *)name { [_name release]; _name = [name retain]; } @end Using newer Objective-C 2.0 syntax as used in Mac OS X 10.6, iOS 4 and Xcode 3.2, generating the same code as described above: @interface Student : NSObject @property (nonatomic, retain) NSString *name; @end @implementation Student @synthesize name = _name; @end And starting with OS X 10.8 and iOS 6, while using Xcode 4.4 and up, syntax can be even simplified: @interface Student : NSObject @property (nonatomic, strong) NSString *name; @end @implementation Student //Nothing goes here and it's OK. @end Perl package Student; sub new { bless {}, shift; } sub set_name { my $self = shift; $self->{name} = $_[0]; } sub get_name { my $self = shift; return $self->{name}; } 1; Or, using Class::Accessor package Student; use base qw(Class::Accessor); ->follow_best_practice; Student->mk_accessors(qw(name)); 1; Or, using the Moose Object System: package Student; use Moose; # Moose uses the attribute name as the setter and getter, the reader and writer