- rather than solving the problem as a single unit (one large problem), break it into sub-problem and solbe sub-problems. When coding these sub-problems you can employ functions.
Local Variable | Glocal Variable | Instance Variable - in a class | |
---|---|---|---|
Definition | introduced inside a function | introduced outside of any functions in the proram | introduced in the constructor of a class |
Scopt | the funstion it is defined in | the entire program | the entire class it is defined in |
Lifetime | until the function it is introduced in comes to an end | until the proram comes to an end | it can be used as long as the object can be accessed |
- encapsulation is the mechanism for restricting the access to some of an object components
- Methods defined in the superclass can be used in subclasses. Therefore, it is good because:
- can re-use code
- can reduce duplicate code
- save time in programming due o reuseability of code
- subclasses bcome more manageable
- A method in a subclass may contain a different set of statements from the method in the superclass
- The method in the subclass is said to override the method in the superclass