Take any value class (e.g., MyCourse or Square) and make it into a handle class. What are the differences?
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:14.11
All Answers
total answers (1)
SquareH.m
classdef SquareH < handle
properties
side = 1;
end
methods
function obj = SquareH(s)
if nargin == 1
obj.side = s;
end
end
function outarg = area(obj)
outarg = obj.side ^ 2;
end
function disp(obj)
fprintf('The square has side %.2f\n', obj.side)
end
end
end
>> vsq1 = Square(3)
vsq1 =
The square has side 3.00
>> vsq2 = vsq1
vsq2 =
The square has side 3.00
>> vsq1.side = 5
vsq1 =
The square has side 5.00
>> vsq2
vsq2 =
The square has side 3.00
>>
>> hsq1 = SquareH(3)
hsq1 =
The square has side 3.00
>> hsq2 = hsq1
hsq2 =
The square has side 3.00
>> hsq1.side = 5
hsq1 =
The square has side 5.00
>> hsq2
hsq2 =
The square has side 5.00
need an explanation for this answer? contact us directly to get an explanation for this answer