In [41]:
(1+2)::AbstractFloat
In [42]:
(1+2)::Int
Out[42]:
In [43]:
function foo() x::Int8 = 100
x
end
Out[43]:
In [49]:
x = foo()
100
typeof(x)
Int8
Out[49]:
In [34]:
workspace()
type Employee
firstName::String
lastName::String
id::Int64
end
In [35]:
emp1=Employee("John", "Frusciante", 1)
println(emp1.firstName)
println(emp1.lastName)
println(emp1.id)
In [36]:
# User defined types can be changed
emp1.firstName="Frederick"
emp1.lastName="Chopin"
emp1
Out[36]:
In [37]:
# Julia pass the objects to function by reference, so any changes you made to the object inside a function are visible
#outside also
function changeEmployee(emp::Employee,firstName,lastName,id)
emp.firstName=firstName
emp.lastName=lastName
emp.id=id
end
changeEmployee(emp1,"Django","Reinhardt",1234)
emp1
Out[37]:
In [38]:
#You can create immutable type using the keyword immutable
In [39]:
immutable Student
id::Int64
name::String
end
stud1=Student(1, "Bill")
Out[39]:
In [40]:
stud1.id=5
In [ ]: