classdef Course < handle
properties
courseName
stdent
end
properties ( Access= private)
lastIDX=1
end
methods
function obj= Course(courseName, capacity)
obj.courseName= courseName
obj.stdent= cell(capacity,1)
end
function addStudent(obj,stdent)
if obj.lastIDX > numel(obj.stdent)
fprintf(2,'sorry class is full`an');
return
end
obj.stdent(obj.lastIDX)=stdent;
obj.lastIDX= obj.lastIDX +1;
end
function printClass(obj)
fprintf('course name = %s\n ', obj.courseName)
fprintf('Enroled =%d , capacity =%d\n', obj.lastIDX-1, length(obj.stdent));
for i =1:obj.lastIDX-1
fprintf('ID =%d, name = %s\n', i, obj.stdent{i}.name);
end
end
end
end
StudentTest1.m
classdef studentTest1 < handle
properties
name
end
methods
function obj=studentTest1(name)
if nargin > 0
obj.name=name;
end
end
function delete(obj)
fprintf('--Student Destructor: %s\n',obj.name);
end
end
end
c = Course('AAA',3);
for i = 1 :4
name= fprintf('amro%d',i);
fprintf('Adding student :%s\n', name)
c.addStudent(name);
end
c.printClass()
clear c
but receiving error :
Error using Course
The specified superclass 'handle' contains a parse error, cannot be found on MATLAB's search path or is shadowed by another file with the same name.
1 Comment
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/313616-class-association-has-error#comment_408501
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/313616-class-association-has-error#comment_408501
Sign in to comment.