- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is 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.
Example
public class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }
Now, based on the above example, in Object-Oriented terms, the following are true −
- Animal is the superclass of Mammal class.
- Animal is the superclass of Reptile class.
- Mammal and Reptile are subclasses of Animal class.
- Dog is the subclass of both Mammal and Animal classes.
Example
class Animal { } class Mammal extends Animal { } class Reptile extends Animal { } public class Dog extends Mammal { public static void main(String args[]) { Animal a = new Animal(); Mammal m = new Mammal(); Dog d = new Dog(); System.out.println(m instanceof Animal); System.out.println(d instanceof Mammal); System.out.println(d instanceof Animal); } }
Output
true true true
- Related Articles
- What is Has-a relationship in Java?
- is-a relationship in Java
- What Is Symbiotic Relationship
- inheritance(is-a) v/s composition (has-a) relationship in Java
- What is Entity-Relationship Modeling?
- HAS-A relationship in Java
- What is an Entity relationship model in DBMS?
- What is the meaning of symbiotic relationship?
- What is the degree of relationship set in DBMS?
- What is the relationship between correlation and covariance?
- What is the relationship between Cookies and Cybersecurity?
- What is the relationship between Km and m?
- What is the nature of Line Staff Relationship?
- What is the relationship between force and pressure?
- What is the relationship between force and acceleration ?

Advertisements