class vehicle { }
class car extends vehicle {
function accelerate() {
// code here
}
}
class motorbike extends vehicle {
function accelerate () {
// code here
}
}
We can clearly see the duplication above of the 2 accelerate methods. What if e pull these up into the vehicle parent class? Lets see how:
class vehicle{
function accelerate (){
// code here
}
class car extends vehicle {}
class motorbike extends vehicle {}
No comments:
Post a Comment