01-11-2012, 03:23 PM
Constructors & Polymorphism
Constructors.ppt (Size: 47 KB / Downloads: 28)
Quiz Observations
Java has 3 visibility / inheritance modifiers
The default visibility is similar to but different from protected
i.e. 4 states
Local variables (within methods) are never visible outside of the method (or class)
Class instance variables (regardless of modifier) are visible throughout the class
More On Constructors
The constructor identifier is identical to the class identifier
If we do not define any constructors
One will be provided for us
If we do define any constructors
We must define the default constructor
Constructors without arguments are considered default constructors
Constructors in a Hierarchy
If our class is an extension of another
When our constructor is called
(previously) Instance variables are created & initialized
Our parent's constructor is called
It's parent's constructor is called
And so on, until Object's constructor is called
Since we can overload constructors, which constructor is called?
Matching signatures
Polymorphism
Latin
Having the properties of ...
shape
many
Having the properties of many different shapes
We determine the action based on the object
Rather than the expected object
Method Overloading
We can have several methods with the same name
But different argument lists
e.g., different signatures
Why is this useful?
We want similar behavior for different types of data
More Definitions
Private
A feature which is accessible only by methods of this class
Protected
A feature which is accessible only by methods of this class, it's children, and other classes
Public
A feature which is accessible by any method in any other class
Default
Same as protected, except, that it is not inherited or accessible outside of the current package