Java IS-A relationship
Contents
Java - Inheritance Basics :
No | Term | Definition |
---|---|---|
1 | Inheritance | Inheritance is a process where one object acquires the properties of another object |
2 | Subclass | Class which inherits the properties of another object is called as subclass |
3 | Superclass | Class whose properties are inherited by subclass is called as superclass |
4 | Keywords Used | extends and implements |
IS-A Relationship with Example :
IS-A is a way of saying : This object is a type of that object.
public class Vehicle{ } public class FourWheeler extends Vehicle{ } public class TwoWheeler extends Vehicle{ } public class WagonR extends FourWheeler{ }
Conclusions from above Example :
From the above example we can say that -
- Vehicle is the superclass of TwoWheeler class.
- Vehicle is the superclass of FourWheeler class.
- TwoWheeler and FourWheeler are sub classes of Vehicle class.
- WagonR is the subclass of both FourWheeler and Vehicle classes.
IS-A relationship of above example is -
TwoWheeler IS-A Vehicle FourWheeler IS-A Vehicle WagonR IS-A FourWheeler
Hence
WagonR IS-A Vehicle