MATLAB Object-Oriented Programming

(Joyce) #1
end
end

The CarPainter class requires its subclasses to define a method called paint:

classdef CarPainter < handle
methods (Abstract)
paint(carobj,colorobj)
end
end

Define an instance of the Cars class:

c1 = Cars.Compact;

The color of this car is Greenish, as defined by the Colors.Greenish enumeration:

c1.Color

ans =

Greenish

Use the paint method to change the car color:

c1.paint(Colors.Reddish)
c1.Color

ans =

Reddish

See Also


Related Examples



  • “Save and Load Enumerations” on page 14-45

  • “Enumerations for Property Values” on page 14-17


14 Enumerations

Free download pdf