student.c: #include <stdlib.h> #include <string.h> #include "student.h" struct student { int age; char *name; }; student *student_new(int age, char *name) { student *s = malloc(sizeof(student)); s->name = strdup(name); s->age = age; return s; } void student_delete(student *s) { free(s->name); free(s); } void student_set_age(student *s, int age) { s->age = age; } int student_get_age(student *s) { return s->age; } char *student_get_name(student *s) { return s->name; } In file main.c: #include <stdio.h> #include "student.h" int main(void) { student *s = student_new(19, "Maurice"); char *name = student_get_name(s); int old_age = student_get_age(s); printf("%s's old age = %i\n", name, old_age); student_set_age(s, 21); int new_age = student_get_age(s); printf("%s's new age = %i\n", name, new_age); student_delete(s); return 0; } In file Makefile: all: out.txt; cat $< out.txt: main; ./$< > $@ main: main.o student.o main.o student.o: student.h clean: ;$(RM) *.o out.txt main C++ In file Student.h: #ifndef STUDENT_H #define STUDENT_H #include <string> class Student { public: Student(const std::string& name); const std::string& name() const; void name(const std::string& name); private: std::string name_; }; #endif In file Student.cpp: #include "Student.h" Student::Student(const std::string& name) : name_(name) { } const std::string& Student::name() const { return name_; } void Student::name(const std::string& name) { name_ = name; } C# This example illustrates the C# idea of properties, which are a special type of class member. Unlike Java, no explicit methods are defined; a public 'property' contains the logic to handle the actions. Note use of the built-in (undeclared) variable value. public class Student { private string name; /// <summary> /// Gets or sets student's name /// </summary> public string Name { get { return name; } set { name = value; } } } In later C# versions (.NET Framework 3.5 and above), this example may be abbreviated as follows, without declaring the private variable name. public class Student { public string Name { get; set; } } Using the abbreviated syntax means that the underlying variable is no longer available from inside the class. As a result, the set portion of the property must be present for assignment. Access can be restricted with a set-specific access modifier. public class Student { public string Name { get; private set; } } Common Lisp In Common Lisp Object System, slot specifications within class definitions may specify any of the :reader, :writer and :accessor options (even multiple times) to define reader methods, setter methods and accessor methods (a reader method and the respective setf method). Slots