Containership in Java is a relationship between classes where one class (the container) contains an object of another class (the contained). This relationship is also known as "has-a" relationship.
Has-a relationships can be used to represent a variety of real-world relationships, such as:
A person has a car.
A company has employees.
A house has a kitchen.
For example, a Car class could contain an Engine object. The Car class would be the container class, and the Engine class would be the contained class. This relationship would allow the Car class to access the methods and properties of the Engine class.
Containership lets a class obtain objects of another class as member data. Like class A can obtain an object of class B ,e.g b1 as member. So here class A becomes container class and class B becomes contained class.
containership does not have such modes as - public, private, protected .
properties of contained object can not be modified.
Containership is some kind of has-a relationship( e . g Class A has an object of class B as it’s member)
Containership is the ability of a class to contain objects of different classes as member data
But if a class is contained in another, the container does not get the ability to change or add behavior to the contained
Containership is used in Java to create complex data structures out of simpler ones. It also allows for code reuse and modularity.
source code link :-
previous code link :-
Sur cette page du site, vous pouvez voir la vidéo en ligne what is containership in java | composition in java | durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur LearningPointAabid 16 novembre 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 118 fois et il a aimé 12 téléspectateurs. Bon visionnage!