June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -14,7 +14,7 @@ class MyClass
|
|||
]
|
||||
}
|
||||
|
||||
program =
|
||||
public program =
|
||||
[
|
||||
// instantiate the class
|
||||
var instance := MyClass new.
|
||||
|
|
|
|||
20
Task/Classes/Julia/classes.julia
Normal file
20
Task/Classes/Julia/classes.julia
Normal 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
|
||||
17
Task/Classes/Processing/classes-1
Normal file
17
Task/Classes/Processing/classes-1
Normal 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"
|
||||
}
|
||||
}
|
||||
5
Task/Classes/Processing/classes-2
Normal file
5
Task/Classes/Processing/classes-2
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// instantiate the class:
|
||||
ProgrammingLanguage processing = new ProgrammingLanguage("Processing");
|
||||
|
||||
// call the method:
|
||||
processing.sayHello();
|
||||
Loading…
Add table
Add a link
Reference in a new issue