Call an object method: Difference between revisions

Content added Content deleted
(Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag)
m (→‎{{header|Kotlin}}: changed syntax highlight to kotlin)
Line 811: Line 811:
masskg(x) = x.weight
masskg(x) = x.weight
=={{header|Kotlin}}==
=={{header|Kotlin}}==
Kotlin does not have static methods as such but they can be easily simulated by 'companion object' methods :
Kotlin does not have static methods, but they can be easily simulated by <code>companion object</code> methods.

<syntaxhighlight lang="scala">class MyClass {
<syntaxhighlight lang="kotlin">class MyClass {
fun instanceMethod(s: String) = println(s)
fun instanceMethod(s: String) = println(s)


Line 820: Line 821:
}
}


fun main(args: Array<String>) {
fun main() {
val mc = MyClass()
val mc = MyClass()
mc.instanceMethod("Hello instance world!")
mc.instanceMethod("Hello instance world!")
Line 831: Line 832:
Hello static world!
Hello static world!
</pre>
</pre>

=={{header|Latitude}}==
=={{header|Latitude}}==