pointObject.setX(200.0);
pointObject.x = 200.0;
private
/public
, static
, final
, class
, methods.
Say you go to the ATM of BlueBank Inc. It collects a PIN in an object.
But... you belong to RedBank Plc., which has its own software. |
||
How does BlueBank send RedBank your details to confirm?
The object BlueBank has wasn't written by programmers at RedBank, so it is bound to be different from what they want.
BlueBank could have a class for every bank it deals with, but that would be complicated. |
Instead, all the banks design a class description that has the information they need.
All banks promise the objects they send will match this class description as a minimum. |
||
The objects can have other stuff as well, but they must match the description at the least. |
BlueBankRequest Methods: getPin() setPin()
|
...is a subtype of... |
GenericRequest Methods demanded: getPin()
|
There's nothing to stop RedBank also developing its own version with other methods along with getPin()
.
|
||
Because the |
||
|
getPin
code in GenericRequest
could be:
public class GenericRequest {
protected int pin;
public int getPin() {
return pin;
}
}
class BlueBankRequest extends GenericRequest {
void setPin(int pinIn) {
pin = pinIn;
}
}
pin
variable and getPin
are inherited from GenericRequest
.
class BlueBankRequest extends GenericRequest {
public BlueBankRequest() {
super("Cheshire Cat Banking plc.");
}
}
super.
to refer to the Superclass methods and variables in the same way as we use this.
to refer to the present class.
final
they can't be overridden by the Subclass. final
Classes can't be inherited.
abstract class GenericRequest {
int pin = 0;
int account = 0;
void setAccNumber(int accountIn) {
account = accountIn;
}
abstract int getPin () ;
}
class BlueBankRequest extends GenericRequest {
int getPin () {
return pin;
}
}
BlueBankRequest
objects have the setAccNumber
method without defining it, but they must define getPin
because all GenericRequest
inheritors must have it.
route66
instantiates Freeway
which inherits Road
which inherits Line
.
dale
instantiates Human
which inherits Primate
which inherits Mammal
with inherits Animal
which inherits Agent
.
class BlueBankRequest extends GenericRequest {