Complete the code to define a property named age in the class.
classdef Person
properties
[1]
end
endfunction or methods inside the properties block.The properties block defines variables for the class. Here, age is a property.
Complete the code to define a method named greet inside the class.
classdef Person
methods
function [1](obj)
disp('Hello!')
end
end
endThe method name follows the function keyword. Here, greet is the method name.
Fix the error in the method definition by completing the code.
classdef Person
properties
name
end
methods
function obj = [1](newName)
obj.name = newName;
end
end
endThe constructor method must have the same name as the class, which is Person.
Fill both blanks to create a method that returns the name property.
classdef Person
properties
name
end
methods
function [1] = getName(obj)
[2] = obj.name;
end
end
endobj as the output.The method output variable is declared after the function keyword, and the output is assigned inside the method.
Fill all three blanks to define a method that sets the age property.
classdef Person
properties
age
end
methods
function obj = [1](obj, [2])
obj.[3] = [2];
end
end
endThe method name is setAge, the input argument is newAge, and the property age is set to this input.
