With the exception of static methods, you must pass an object of the class explicitly to a MATLAB method?
Show older comments
Method Syntax said:“With the exception of static methods, you must pass an object of the class explicitly to a MATLAB method.”
Static Methods said:"Therefore, you can call static methods without creating an object of the class."
There is a constructor MyClock.It is not a static Method. It didn't pass an object of the calsss,but it is working!
Why?
If I can call methods without creating an object of the class. Why do I need static methods?
The only value of static methods is to allow the creation of a method within a class that does not require input arguments?
classdef MyClock
properties
Time;
end
methods
function obj=MyClock()
obj.Time=datetime;
end
function val=get.Time(obj)
val=datetime;
end
end
end
It is weird,I delete get.Time input arguments 'obj' . I creat a MyClock object T: T=MyClock;
I find T.Time is non-existent. I set a breaking point in obj.Time=datetime;
I find the program did not execute get.Time block!
If I type:
T=MyClock;
T
It will call get.Time. T.Time is non-existent. It is make sense!
But the program did not execute get.Time block ,Why is T.Time non-existent?
classdef MyClock
properties
Time;
end
methods
function obj=MyClock()
obj.Time=datetime;
end
function val=get.Time() %I delete get.Time input arguments 'obj'
val=datetime;
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Deploy to .NET Applications Using MWArray API in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!