25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14. Top-level Specification (<strong>VDM</strong>++ and <strong>VDM</strong>-RT)<br />

end A<br />

class B is subclass of A<br />

instance variables<br />

v4 : Atype --inherited from A<br />

operations<br />

BInit: () ==> ()<br />

BInit() ==<br />

(AInit(1,true,2.718); --OK: can access protected members<br />

--in superclass<br />

v4 := compare(v1); --OK since v1 is public<br />

v3 := 3.5;<br />

--OK since v3 protected and this<br />

--is a subclass of A<br />

v2 := false<br />

--illegal since v2 is private to A<br />

)<br />

end B<br />

class C<br />

instance variables<br />

a: A := new A();<br />

b: B := new B();<br />

operations<br />

CInit: () ==> A‘Atype--types are class attributes<br />

CInit() ==<br />

(a.AInit(3,false,1.1);<br />

--illegal since AInit is protected<br />

b.BInit();<br />

--illegal since BInit is (by default)<br />

--private<br />

let - = a.compare(b.v3) in skip;<br />

--illegal since C is not subclass<br />

--of A so b.v3 is not available<br />

return b.compare(B‘Avalue)<br />

--OK since compare is a public instance<br />

--attribute and Avalue is public class<br />

--attribute in B<br />

135

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!