Data encapsulation examples

C++

Class A has an integer member called index. This member will be hidden from all code in the project except the code for the class A itself.

Class A has a function doIncrement() which alters the index member. It has another function getIndex() that returns the value of the index member.

All other code may alter the index member of an A object only by calling the doIncrement() function, and can only know the value of the index member by calling the getIndex() function.

encapsulation.cc

C

You can write a perfectly well encapsulated module in C.

encapsulation.c

Perl, Python, JavaScript

These languages really don't encapsulate data well. You can give member data a funny name and plead with users not to alter it, but really all member data in these languages is exposed.

FORTRAN 90

Yes.

FORTRAN

Not really meaningful in this language