1245:
A member variable is a member of a class (class variable) or a member of an object instantiated from that class (instance variable). It must be declared within a class, but not within the body of a method of the
1269:
1264:
72:
68:
20:
43:
39:
30:
54:
1212:
35:
684:# When a new Poodle instance is created, by default it is untrained. The 'trained' variable
690:# An instance variable is defined within an instance method and is a member of the Poodle instance
666:# The "class instance variable" is defined within the class body with a single at-sign
77:
1202:
669:# and describes data about only the Poodle class. It makes no claim about its parent class
1207:
59:
1258:
1086:-- In a Lua object is a metatable and its member variables are table key-value pairs.
687:# is local to the initialize method and is used to set the instance variable @trained
81:, where each instance of the class has its own independent copy of the variable.
1233:
16:
Variable associated with a specific object, and accessible for all its methods
606:# and describes data about all Dogs *and* their derived Dog breeds (if any)
591:
Ruby has three member variable types: class, class instance, and instance.
603:# The class variable is defined within the class body with two at-signs
1083:-- The first table argument is our object's member variables.
1017:--- @field foo number Example "member variable".
67:), where only one copy of the variable is shared with all
1155:-- Overwrite the "foo" member variable to 10.
963:// Overwrite the "foo" member variable to 10.
816:* Member variables may be public, protected or private.
291:
variable is equal to the lifespan of "this"
57:languages, these are distinguished into two types:
1125:-- Set the "foo" member variable to 5.
939:// Set the "foo" member variable to 5.
672:# or any possible subclass derived from Poodle
282:/* This is a member variable - a new instance
8:
288:new instance of Foo. The lifespan of this
285:of this variable will be created for each
1236:. Richard G Baldwin Programming Tutorials
249:// This is a local variable. Its lifespan
1224:
7:
1056:--- Creates an object from example.
810:* Example instance member variable.
38:that is associated with a specific
252:// is determined by lexical scope.
14:
1232:Richard G. Baldwin (1999-03-10).
843:* Example static member variable.
1234:"Q - What is a member variable?"
936:// Create a new Example object.
1:
873:* Example constructor method.
42:, and accessible for all its
1122:-- Create an example object.
1270:Variable (computer science)
1265:Object-oriented programming
21:object-oriented programming
1286:
1008:
792:
585:
486:
318:
207:
93:
65:static member variables
55:class-based programming
1213:Property (programming)
1059:--- @return example_c
1014:--- @class example_c
27:(sometimes called a
879:* @param int $ foo
114:// Member variable
78:instance variables
186:// Local variable
1277:
1249:
1248:
1242:
1241:
1229:
1192:
1189:
1186:
1183:
1180:
1177:
1174:
1171:
1168:
1165:
1162:
1159:
1156:
1153:
1150:
1147:
1144:
1141:
1138:
1135:
1132:
1129:
1126:
1123:
1120:
1117:
1114:
1111:
1108:
1105:
1102:
1099:
1096:
1093:
1090:
1087:
1084:
1081:
1078:
1075:
1072:
1069:
1066:
1063:
1060:
1057:
1054:
1051:
1048:
1045:
1042:
1039:
1036:
1033:
1030:
1027:
1024:
1021:
1018:
1015:
1012:
1011:--region example
1000:
997:
994:
991:
988:
985:
982:
979:
976:
973:
970:
967:
964:
961:
958:
955:
952:
949:
946:
943:
940:
937:
934:
931:
928:
925:
922:
919:
916:
913:
910:
907:
904:
901:
898:
895:
892:
889:
886:
883:
880:
877:
874:
871:
868:
865:
862:
859:
856:
853:
850:
847:
844:
841:
838:
835:
832:
829:
826:
823:
820:
817:
814:
811:
808:
805:
802:
799:
796:
784:
781:
778:
775:
772:
769:
766:
763:
760:
757:
754:
751:
748:
745:
742:
739:
736:
733:
730:
727:
724:
721:
718:
715:
712:
709:
706:
703:
700:
697:
694:
691:
688:
685:
682:
679:
676:
673:
670:
667:
664:
661:
658:
655:
652:
649:
646:
643:
640:
637:
634:
631:
628:
625:
622:
619:
616:
613:
610:
607:
604:
601:
598:
595:
592:
589:
577:
574:
571:
568:
565:
562:
559:
556:
553:
550:
547:
544:
541:
538:
535:
532:
529:
526:
523:
520:
517:
514:
511:
508:
505:
502:
499:
496:
493:
490:
478:
475:
472:
469:
466:
463:
460:
457:
454:
451:
448:
445:
442:
439:
436:
433:
430:
427:
424:
421:
418:
415:
412:
409:
406:
403:
400:
397:
394:
391:
388:
385:
382:
379:
376:
373:
370:
367:
364:
361:
358:
355:
352:
349:
346:
343:
340:
337:
334:
331:
328:
325:
322:
310:
307:
304:
301:
298:
295:
292:
289:
286:
283:
280:
277:
274:
271:
268:
265:
262:
259:
256:
253:
250:
247:
244:
241:
238:
235:
232:
229:
226:
223:
220:
217:
214:
211:
199:
196:
193:
190:
187:
184:
181:
178:
175:
172:
169:
166:
163:
160:
157:
154:
151:
148:
145:
142:
139:
136:
133:
130:
127:
124:
121:
118:
115:
112:
109:
106:
103:
100:
97:
48:member functions
1285:
1284:
1280:
1279:
1278:
1276:
1275:
1274:
1255:
1254:
1253:
1252:
1239:
1237:
1231:
1230:
1226:
1221:
1203:Global variable
1199:
1194:
1193:
1190:
1187:
1184:
1181:
1178:
1175:
1172:
1169:
1166:
1163:
1160:
1157:
1154:
1151:
1148:
1145:
1142:
1139:
1136:
1133:
1130:
1127:
1124:
1121:
1118:
1115:
1112:
1109:
1106:
1103:
1100:
1097:
1094:
1091:
1088:
1085:
1082:
1079:
1076:
1073:
1070:
1067:
1064:
1061:
1058:
1055:
1052:
1049:
1046:
1043:
1040:
1037:
1034:
1031:
1028:
1025:
1022:
1019:
1016:
1013:
1010:
1007:
1002:
1001:
998:
995:
992:
989:
986:
983:
980:
977:
974:
971:
968:
965:
962:
959:
956:
953:
950:
947:
944:
941:
938:
935:
932:
929:
926:
923:
920:
917:
914:
911:
908:
905:
902:
899:
896:
893:
890:
887:
884:
881:
878:
875:
872:
869:
866:
863:
860:
857:
854:
851:
848:
845:
842:
839:
836:
833:
830:
827:
824:
821:
818:
815:
812:
809:
806:
803:
800:
797:
794:
791:
786:
785:
782:
779:
776:
773:
770:
767:
764:
761:
758:
755:
752:
749:
746:
743:
740:
737:
734:
731:
728:
725:
722:
719:
716:
713:
710:
707:
704:
701:
698:
695:
692:
689:
686:
683:
680:
677:
674:
671:
668:
665:
662:
659:
656:
653:
650:
647:
644:
641:
638:
635:
632:
629:
626:
623:
620:
617:
614:
611:
608:
605:
602:
599:
596:
593:
590:
587:
584:
579:
578:
575:
572:
569:
566:
563:
560:
557:
554:
551:
548:
545:
542:
539:
536:
533:
530:
527:
524:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
491:
488:
485:
480:
479:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
425:
422:
419:
416:
413:
410:
407:
404:
401:
398:
395:
392:
389:
386:
383:
380:
377:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
344:
341:
338:
335:
332:
329:
326:
323:
320:
317:
312:
311:
308:
305:
302:
299:
296:
294:instance of Foo
293:
290:
287:
284:
281:
278:
275:
272:
269:
266:
263:
260:
257:
254:
251:
248:
245:
242:
239:
236:
233:
230:
227:
224:
221:
218:
215:
212:
209:
206:
201:
200:
197:
194:
191:
188:
185:
182:
179:
176:
173:
170:
167:
164:
161:
158:
155:
152:
149:
146:
143:
140:
137:
134:
131:
128:
125:
122:
119:
116:
113:
110:
107:
104:
101:
98:
95:
92:
87:
60:class variables
25:member variable
17:
12:
11:
5:
1283:
1281:
1273:
1272:
1267:
1257:
1256:
1251:
1250:
1223:
1222:
1220:
1217:
1216:
1215:
1210:
1208:Local variable
1205:
1198:
1195:
1009:
1006:
1003:
793:
790:
787:
586:
583:
580:
487:
484:
481:
319:
316:
313:
208:
205:
202:
94:
91:
88:
86:
83:
15:
13:
10:
9:
6:
4:
3:
2:
1282:
1271:
1268:
1266:
1263:
1262:
1260:
1247:
1235:
1228:
1225:
1218:
1214:
1211:
1209:
1206:
1204:
1201:
1200:
1196:
1173:-- Prints 10.
1004:
984:// Prints 10.
788:
581:
522:make-instance
482:
314:
203:
89:
84:
82:
80:
79:
74:
70:
66:
63:(also called
62:
61:
56:
51:
49:
45:
41:
37:
33:
32:
26:
22:
1244:
1238:. Retrieved
1227:
1092:setmetatable
909:// Sets foo.
783:#=> false
780:has_manners?
771:#=> false
729:has_manners?
85:For Examples
76:
64:
58:
52:
47:
28:
24:
18:
1119:--endregion
891:__construct
849:* @var bool
651:#=> true
483:Common Lisp
1259:Categories
1240:2011-08-12
1219:References
1110:example_mt
1035:example_mt
822:* @var int
696:initialize
567:slot-value
540:slot-value
1137:example_c
1065:example_c
1050:example_c
1023:example_c
990:$ example
966:$ example
942:$ example
855:protected
360:@property
69:instances
1197:See also
1062:function
888:function
795:<?php
732:@trained
714:@trained
609:@@sniffs
573:'bar
546:'bar
525:'foo
492:defclass
333:__init__
36:variable
1182:example
1158:example
1131:example
1044:__index
951:Example
801:Example
720:trained
702:trained
432:new_bar
414:new_bar
216:Program
71:of the
44:methods
34:) is a
29:member
1246:class.
1089:return
912:$ this
885:public
858:static
828:public
747:Poodle
675:@sheds
657:Poodle
648:sniffs
513:defvar
396:setter
378:return
315:Python
270:public
237:String
225:static
222:public
210:public
189:return
153:newBar
138:newBar
126:setBar
117:public
75:; and
40:object
1176:print
1128:local
1032:local
1020:local
993:->
969:->
924:$ foo
915:->
900:$ foo
864:$ bar
834:$ foo
798:class
768:sheds
762:class
708:false
681:false
654:class
642:class
597:class
561:print
462:print
321:class
273:class
213:class
132:const
96:class
73:class
31:field
987:echo
660:<
636:mutt
621:mutt
615:true
582:Ruby
534:setf
426:_bar
420:self
408:self
390:@bar
387:_bar
381:self
372:self
351:_bar
345:self
339:self
240:args
231:main
228:void
204:Java
180:rect
168:main
123:void
23:, a
1188:foo
1164:foo
1143:new
1116:end
1104:foo
1098:foo
1077:foo
1071:new
1005:Lua
996:foo
972:foo
948:new
918:foo
897:int
870:/**
861:int
840:/**
831:int
807:/**
789:PHP
753:new
738:end
735:end
726:def
723:end
693:def
663:Dog
633:new
627:Dog
618:end
600:Dog
552:100
504:bar
495:foo
474:bar
459:100
453:bar
441:Foo
402:bar
399:def
366:bar
363:def
330:def
324:Foo
303:bar
300:int
276:Foo
258:foo
255:Foo
177:Foo
165:int
147:bar
135:int
108:bar
105:int
99:Foo
90:C++
53:In
50:).
19:In
1261::
1243:.
1170:10
1107:},
1095:({
1029:{}
978:10
960:);
882:*/
852:*/
825:*/
594:*/
588:/*
576:))
528:))
507:))
498:()
444:()
417:):
375:):
342:):
297:*/
171:()
162:};
1191:)
1185:.
1179:(
1167:=
1161:.
1152:)
1149:5
1146:(
1140:.
1134:=
1113:)
1101:=
1080:)
1074:(
1068:.
1053:}
1047:=
1041:{
1038:=
1026:=
999:;
981:;
975:=
957:5
954:(
945:=
933:}
930:}
927:;
921:=
906:{
903:)
894:(
876:*
867:;
846:*
837:;
819:*
813:*
804:{
777:.
774:p
765:.
759:.
756:p
750:.
744:=
741:p
717:=
711:)
705:=
699:(
678:=
645:.
639:.
630:.
624:=
612:=
570:f
564:(
558:(
555:)
549:)
543:f
537:(
531:(
519:(
516:f
510:(
501:(
489:(
477:)
471:.
468:f
465:(
456:=
450:.
447:f
438:=
435:f
429:=
423:.
411:,
405:(
393:.
384:.
369:(
357:0
354:=
348:.
336:(
327::
309:}
306:;
279:{
267:}
264:}
261:;
246:{
243:)
234:(
219:{
198:}
195:;
192:0
183:;
174:{
159:}
156:;
150:=
144:{
141:)
129:(
120::
111:;
102:{
46:(
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.