20.03.2015 Views

The Objective Caml system release 3.06 - The Caml language - Inria

The Objective Caml system release 3.06 - The Caml language - Inria

The Objective Caml system release 3.06 - The Caml language - Inria

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

38<br />

# end;;<br />

class point :<br />

int -><br />

object<br />

val mutable x : int<br />

method get_offset : int<br />

method get_x : int<br />

method move : int -> unit<br />

end<br />

3.5 Private methods<br />

Private methods are methods that do not appear in object interfaces. <strong>The</strong>y can only be invoked<br />

from other methods of the same object.<br />

# class restricted_point x_init =<br />

# object (self)<br />

# val mutable x = x_init<br />

# method get_x = x<br />

# method private move d = x <br />

object<br />

val mutable x : int<br />

method bump : unit<br />

method get_x : int<br />

method private move : int -> unit<br />

end<br />

# let p = new restricted_point 0;;<br />

val p : restricted_point = <br />

# p#move 10;;<br />

This expression has type restricted_point<br />

It has no method move<br />

# p#bump;;<br />

- : unit = ()<br />

Private methods are inherited (they are by default visible in subclasses), unless they are hidden by<br />

signature matching, as described below.<br />

Private methods can be made public in a subclass.<br />

# class point_again x =<br />

# object (self)<br />

# inherit restricted_point x<br />

# method virtual move : _

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

Saved successfully!

Ooh no, something went wrong!