what is containership in java | composition in java |

Pubblicato il: 16 novembre 2023
sul canale di: LearningPointAabid
118
12

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 :-


In questa pagina del sito puoi guardare il video online what is containership in java | composition in java | della durata di ore minuti seconda in buona qualità , che l'utente ha caricato LearningPointAabid 16 novembre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 118 volte e gli è piaciuto 12 spettatori. Buona visione!