Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. Self always referrs to the instance in which it is called.
  2.  
  3. If you're in a class of type class, it refers to that intance of 'class'. If you're in a class of type Array, self referrs to that instance of 'array'. If you're in a class of type Battleship, self referrs to that instance of battleship.
  4.  
  5. If you are defining a class, let's call it Boat, it depends on where self is called. If it is called outside of a method, it will refer to the 'Class' class, as the 'Boat' class has not been instantiated. This includes using self to define class methods. If you call self inside of a method, it will refer to the intance of 'Boat' class as it has been instantiated before it was called.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement