Chapter 11

12 views3 pages
Chapter 11 – Classes and objects
11.1 What is an object?
Classes can be used to specify blueprints for objects
More on pg 230-231
11.2 ‘Time’ for an example
Example on pg 232
Attributes are also called instance variables
oInstance variables have class scope, ex. they are accessible throughout the class
oThey are usually declared as private, which means they can only be accessed by
the methods of this class and not by methods of other classes
Constructor methods
Characteristics of constructor methods
oAre called upon when a new object is created
oThey have the same name as their class
oParameters if any are often used to give initial values to instance variables
oConstructor methods sometimes do other processing associated with initializing a
new object
oConstructor methods have no return value
Calling a constructor method
A constructor method is called when you create an object of the associated class using
new
Memory is allocated to hold the new object then the appropriate constructor method is
called
Using Timepiece objects
Example on pg 233-234
www.notesolution.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Grade+

Unlimited access to all notes and study guides.

YearlyMost Popular
75% OFF
$9.98/m
Monthly
$39.98/m
Single doc
$39.98

or

You will be charged $119.76 upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.