Section 6 Overloading, Overriding, Runtime Type, and Object Orientation
Encapsulation means the internal wirings (variables/fields/properties) of the class are not visible outside. Instead, the class provides accessor (getter and setter) methods for the properties it supports. In other words, have private fields and have public setters and getters.
In the above situation: .SportsCar is-a
Car ( because SportsCar extends Car )Consider the following declarations:
public class GearBox
{
public void shiftGear(int gearNo){ ... }
}
public interface Movable{ }
public class Car implements Movable
{
private GearBox gb = new GearBox();
}
public class SportsCar extends Car
{
}
.Car has-a
GearBox ( because Car has a variable of class GearBox )
.SportsCar
has-a
GearBox ( because SporstCar is a Car and Car has a GearBox )
.Car and SportsCar is-a Movable (because Car implements Movable and SportsCar
extends Car) Although, this is strictly an is-like-a
relationship but still can be clubbed together with is-arelationship.
Points to remember: . Overloaded methods are entirely independent methods. Two overloaded methods behave as if they were two methods with different names. Method name is NOT important, it's the signature (ie. method name + parameterlist) that governs the behavior and overloaded methods have different signatures.