Call an object method: Difference between revisions

m
Line 641:
 
=={{header|Julia}}==
module Animal
 
abstract type Animal end
abstract type Dog <: Animal end
abstract type Cat <: Animal end
struct Collie <: Dog
name::String
weight::Float64
end
 
struct Persian <: Cat
name::String
weight::Float64
end
 
#
#
# This function is static: it works on any dog, even on a blank instance, in
# the same way, to produce the same output for anything that isa Dog in type.
#
#
function soundalert(a::T) where T <: Dog
println("Woof!")
end
 
#
#
# This function depends on the class instance's data for its value, so this type
# of function is one way to do an instance method in Jula.
#
#
masskg(x) = x.weight
 
=={{header|Kotlin}}==
4,108

edits