June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -14,7 +14,7 @@ class MyClass
]
}
program =
public program =
[
// instantiate the class
var instance := MyClass new.

View file

@ -0,0 +1,20 @@
abstract type Mammal end
habitat(::Mammal) = "planet Earth"
struct Whale <: Mammal
mass::Float64
habitat::String
end
Base.show(io::IO, ::Whale) = print(io, "a whale")
habitat(w::Whale) = w.habitat
struct Wolf <: Mammal
mass::Float64
end
Base.show(io::IO, ::Wolf) = print(io, "a wolf")
arr = [Whale(1000, "ocean"), Wolf(50)]
println("Type of $arr is ", typeof(arr))
for a in arr
println("Habitat of $a: ", habitat(a))
end

View file

@ -0,0 +1,17 @@
class ProgrammingLanguage
{
// instance variable:
private String name;
// constructor (let's use it to give the instance variable a value):
public ProgrammingLanguage(String name)
{
this.name = name;
// note use of "this" to distinguish the instance variable from the argument
}
// a method:
public void sayHello()
{
println("Hello from the programming language " + name);
// the method has no argument or local variable called "name", so we can omit the "this"
}
}

View file

@ -0,0 +1,5 @@
// instantiate the class:
ProgrammingLanguage processing = new ProgrammingLanguage("Processing");
// call the method:
processing.sayHello();