Inner classes: Difference between revisions

m
→‎{{header|Go}}: Minor changes to preamble.
(Added Go)
m (→‎{{header|Go}}: Minor changes to preamble.)
Line 177:
It is possible to nest structs as the following example shows. However, the problem here is that the nested struct has an anonymous type and the only way to give it methods is via an instance of the Outer struct.
 
In practice it would probably be better to declare the nested struct independently but within the same package and achieve encapsulation by restricting the package to just those two structs.
<syntaxhighlight lang="go">package main
 
9,485

edits