Computer >> Computer tutorials >  >> Programming >> Java

is-a relationship in Java


IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.

public class Animal {
}
public class Mammal extends Animal {
}
public class Reptile extends Animal {
}
public class Dog extends Mammal {
}

Now, if we consider the IS-A relationship, we can say −

  • Mammal IS-A Animal 
  • Reptile IS-A Animal 
  • Dog IS-A Mammal 
  • Hence: Dog IS-A Animal as well