This is the lecture note of CS61A - Lecture 16.
OOP (Object-Oriented Programming)
Objects are organized according to classes.
- A class combines (and abstracts) the storing of information data and functionality on the data (data + methods).
- An object is an instantiation of a class.
Class Statements
Class statements let you create any type of data you want.
1 | 'Jim') a = Account( |
Constructors,
- allocate memory for an object
- initialize an object with values
- return address of the object
Methods
Objects receive messages via dot notation. Dot notation accesses attributes of the instance or its class.
1 | <expression>.<attribute_name> |
Attributes
Class attributes are "shared" across all instances of a class because they are attributes of the class, not the instance.
Code
Code of today's lecture:
1 | class Account: |