Call an object method: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
imported>Acediast
(→‎{{header|COBOL}}: switched to free format)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(3 intermediate revisions by 2 users not shown)
Line 738:
Hello static world!
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn FBClassDemo
// Class
ClassRef class = fn MutableStringClass
// Cocoa base class name as human-readable string
print fn StringFromClass( class )
// Instantiate
CFMutableStringRef mutStr = fn MutableStringNew
// Method with single argument
MutableStringSetString( mutStr, @"Hello, World!" )
print mutStr
// Method with multiple arguments
MutableStringReplaceAllOccurrencesOfString( mutStr, @"World", @"Rosetta Code" )
print mutStr
end fn
 
fn FBClassDemo
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
NSMutableString
Hello, World!
Hello, Rosetta Code!
</pre>
 
=={{header|Go}}==
Go distances itself from the word "object" and from many object oriented concepts. It does however have methods. Any user-defined type in Go can have methods and these work very much like "instance methods" of object oriented languages. The examples below illustrate details of Go methods and thus represent the concept of instance methods.
Line 2,266 ⟶ 2,298:
=={{header|Wren}}==
Note that it's possible in Wren for instance and static methods in the same class to share the same name. This is because static methods are considered to belong to a separate meta-class.
<syntaxhighlight lang="ecmascript"wren>class MyClass {
construct new() {}
method() { System.print("instance method called") }
Line 2,281 ⟶ 2,313:
static method called
</pre>
 
=={{header|XBS}}==
You can call object methods using two types of structures. Classes and Objects.
Line 2,345 ⟶ 2,378:
Zig does not have classes nor objects. Zig's structs, however, can have methods; but they are not special. They are only namespaced functions that can be called with dot syntax.
 
<syntaxhighlight lang="zig">const asserttesting = @import("std").debug.asserttesting;
 
pub const ID = struct {
Line 2,375 ⟶ 2,408:
};
 
assert(person1.// test getAge() ==method 18);call
asserttry testing.expectEqual(ID@as(u7, 18), person1.getAge(person2) == 20);
try testing.expectEqual(@as(u7, 20), ID.getAge(person2));
}</syntaxhighlight>
 
=={{header|zkl}}==
In zkl, a class can be static (there will only exist one instance of the class). A function is always a member of some class but will only be static if it does not refer to instance data.
9,485

edits