Found 7442 Articles for Java

inheritance(is-a) v/s composition (has-a) relationship in Java

Giri Raju
Updated on 17-Jun-2020 07:11:07

869 Views

IS-A RelationshipIS-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 AnimalReptile IS-A AnimalDog IS-A MammalHence: Dog IS-A Animal as wellWith the use of the extends keyword, the subclasses will be able to inherit all the properties of the superclass except for the private properties of the ... Read More

HAS-A relationship in Java

Shriansh Kumar
Updated on 18-Apr-2025 18:46:44

2K+ Views

Java is a programming language that follows the Object-Oriented Programming paradigm. One of the pillars of OOPs is Inheritance, where you can find a relationship between two classes as Parent and Child. This relationship allows these classes to reuse each other's attributes and methods. Java classes can relate to each other in many ways such as, Is-A relationship and Has-A relationship. In this article, we are going to learn the concept of Has-A relationship in Java through examples. HAS-A Relationship in Java Has-A relationship is a type of association where two classes are linked to each other through objects. Here, ... Read More

HAS-A relationship in Java

Shriansh Kumar
Updated on 18-Apr-2025 18:46:44

2K+ Views

Java is a programming language that follows the Object-Oriented Programming paradigm. One of the pillars of OOPs is Inheritance, where you can find a relationship between two classes as Parent and Child. This relationship allows these classes to reuse each other's attributes and methods. Java classes can relate to each other in many ways such as, Is-A relationship and Has-A relationship. In this article, we are going to learn the concept of Has-A relationship in Java through examples. HAS-A Relationship in Java Has-A relationship is a type of association where two classes are linked to each other through objects. Here, ... Read More

HAS-A relationship in Java

Shriansh Kumar
Updated on 18-Apr-2025 18:46:44

2K+ Views

Java is a programming language that follows the Object-Oriented Programming paradigm. One of the pillars of OOPs is Inheritance, where you can find a relationship between two classes as Parent and Child. This relationship allows these classes to reuse each other's attributes and methods. Java classes can relate to each other in many ways such as, Is-A relationship and Has-A relationship. In this article, we are going to learn the concept of Has-A relationship in Java through examples. HAS-A Relationship in Java Has-A relationship is a type of association where two classes are linked to each other through objects. Here, ... Read More

Why multiple inheritance is not supported in Java

Shriansh Kumar
Updated on 14-Apr-2025 10:56:21

43K+ Views

Multiple inheritance is a type of inheritance where a single subclass inherits multiple superclasses. As the name suggests, inheritance is the ability of a class to inherit members of another class. The class whose properties are inherited is called a superclass, whereas the class that inherits a superclass is called a subclass. We use the extends keyword to inherit the members of a class. Unlike other object-oriented programming languages, Java does not support multiple inheritance. As an alternative, we can implement multiple inheritances from a single class. Why Java Does Not Support Multiple Inheritance When a single class inherits the ... Read More

Why multiple inheritance is not supported in Java

Shriansh Kumar
Updated on 14-Apr-2025 10:56:21

43K+ Views

Multiple inheritance is a type of inheritance where a single subclass inherits multiple superclasses. As the name suggests, inheritance is the ability of a class to inherit members of another class. The class whose properties are inherited is called a superclass, whereas the class that inherits a superclass is called a subclass. We use the extends keyword to inherit the members of a class. Unlike other object-oriented programming languages, Java does not support multiple inheritance. As an alternative, we can implement multiple inheritances from a single class. Why Java Does Not Support Multiple Inheritance When a single class inherits the ... Read More

Why multiple inheritance is not supported in Java

Shriansh Kumar
Updated on 14-Apr-2025 10:56:21

43K+ Views

Multiple inheritance is a type of inheritance where a single subclass inherits multiple superclasses. As the name suggests, inheritance is the ability of a class to inherit members of another class. The class whose properties are inherited is called a superclass, whereas the class that inherits a superclass is called a subclass. We use the extends keyword to inherit the members of a class. Unlike other object-oriented programming languages, Java does not support multiple inheritance. As an alternative, we can implement multiple inheritances from a single class. Why Java Does Not Support Multiple Inheritance When a single class inherits the ... Read More

Multilevel inheritance in Java

Govinda Sai
Updated on 10-Dec-2024 19:11:37

86K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape { public void display() { System.out.println("Inside display"); } } class Rectangle extends Shape { public void area() { System.out.println("Inside area"); } } class Cube extends Rectangle { public void volume() { System.out.println("Inside volume"); } } public class Tester { public static void main(String[] arguments) { Cube cube = new Cube(); cube.display(); cube.area(); cube.volume(); } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Multilevel inheritance in Java

Govinda Sai
Updated on 10-Dec-2024 19:11:37

86K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape { public void display() { System.out.println("Inside display"); } } class Rectangle extends Shape { public void area() { System.out.println("Inside area"); } } class Cube extends Rectangle { public void volume() { System.out.println("Inside volume"); } } public class Tester { public static void main(String[] arguments) { Cube cube = new Cube(); cube.display(); cube.area(); cube.volume(); } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Multilevel inheritance in Java

Govinda Sai
Updated on 10-Dec-2024 19:11:37

86K+ Views

Multilevel inheritance - A class inherits properties from a class which again has inherits properties. Example class Shape { public void display() { System.out.println("Inside display"); } } class Rectangle extends Shape { public void area() { System.out.println("Inside area"); } } class Cube extends Rectangle { public void volume() { System.out.println("Inside volume"); } } public class Tester { public static void main(String[] arguments) { Cube cube = new Cube(); cube.display(); cube.area(); cube.volume(); } } Output Inside display Inside area Inside volume Read Also: Java Inheritance

Advertisements