Hello, I am trying to learn classes in Matlab here is a basic question. How can I write two classes A and B in order to represent following structur?
My first class is A and second class is B. Let A has two property as p and q and B has also two property as m and n. Moreover, one of class is subclasses of other.
A.B=B; %Minor question :) which one is a subclass A or B?
A.B.m %should be 3 A.B.n %should be 4
It is a convention to use upper case for the first letter in a class name and lower case for instancies/objects
>> a = A(); >> a.b.m ans = 3
classdef A properties p = 1; q = 2; b = B; end end
classdef B properties m = 3; n = 4; end end
One more example
>> A.B.m ans = 3
classdef A properties ( Constant ) p = 1; q = 2; B = B(); end end
classdef B properties ( Constant ) m = 3; n = 4; end end
However, I don't think this is what you really ask for.
Play games and win prizes!Learn more