Sealed classes and methods: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added "more sensible way") |
(Added FreeBasic) |
||
Line 21: | Line 21: | ||
* [[Inheritance/Single]] |
* [[Inheritance/Single]] |
||
* [[Inheritance/Multiple]] |
* [[Inheritance/Multiple]] |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="vb">Type Parent |
|||
nombre As ZString * 7 |
|||
edad As Byte |
|||
Declare Operator Cast () As String |
|||
End Type |
|||
Operator Parent.cast As String |
|||
Return this.nombre & " is watching the movie..." |
|||
End Operator |
|||
Type Child Extends Parent |
|||
Declare Operator Cast As String |
|||
End Type |
|||
Operator Child.cast As String |
|||
If this.edad < 15 Then |
|||
Return "Sorry, " & this.nombre & ", you are too young to watch the movie." |
|||
Else |
|||
Return this.nombre & " is watching the movie..." |
|||
End If |
|||
End Operator |
|||
Dim As Parent p1, p2 |
|||
p1.nombre = "Donald" : p1.edad = 42 |
|||
p2.nombre = "Dougal" : p2.edad = 12 |
|||
Print p1 |
|||
Print p2 |
|||
Dim As Child c1, c2 |
|||
c1.nombre = "Lisa" : c1.edad = 18 |
|||
c2.nombre = "Fred" : c2.edad = 10 |
|||
Print c1 |
|||
Print c2 |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Donald is watching the movie... |
|||
Dougal is watching the movie... |
|||
Lisa is watching the movie... |
|||
Sorry, Fred, you are too young to watch the movie.</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |