With the exception of static methods, you must pass an object of the class explicitly to a MATLAB method?
古いコメントを表示
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
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Deploy to .NET Applications Using MWArray API についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!