Inner classes: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
 
(One intermediate revision by one other user not shown)
Line 165:
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Go}}
FreeBASIC is not an object-oriented programming language and does not have support for internal classes. However, you can simulate some features of object-oriented programming using Type and Sub.
<syntaxhighlight lang="vbnet">Type Inner
campo As Integer
End Type
 
Type Outer
campo As Integer
interno As Inner
End Type
 
Sub outerMethod(o As Outer)
Print "Outer's field has a value of "; o.field
End Sub
 
Sub innerMethod(o As Outer)
Print "Inner's field has a value of "; o.interno.field
End Sub
 
Dim As Outer o
o.field = 43
o.interno.field = 42
innerMethod(o)
outerMethod(o)
 
Dim As Outer p
p.field = 45
p.interno.field = 44
innerMethod(p)
outerMethod(p)
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as Go entry.</pre>
 
=={{header|Go}}==
Line 391 ⟶ 426:
 
To make things a little more interesting the inner class in the following example also inherits from the outer class. In fact inheritance is the only way for the inner class to access the outer class's instance methods ''directly'' as it is otherwise treated the same as a non-nested class. The only advantage it really offers is to encapsulate closely related classes under the one umbrella .
<syntaxhighlight lang="ecmascriptwren">class Outer {
static makeInner {
class Inner is Outer {
2,122

edits