Q:

Take any value class (e.g., MyCourse or Square) and make it into a handle class. What are the differences?

0

Take any value class (e.g., MyCourse or Square) and make it into a handle class. What are the differences?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now