OOPs in Java
Object Oriented Programming in Java
This is an extension to the previous post which had a brief explanation of Object Oriented Programming in Java.
Here, we will just go through some other important terminologies that are widely used in Java.
Association, Aggregation, and Composition:
These are different types of relationships between classes —
- Association represents a relationship where objects of one class are connected to objects of another class.
- Aggregation represents a “has-a” relationship, where one class contains references to objects of another class.
- Composition is a stronger form of aggregation, where the lifetime of the contained object is managed by the container object.
Method Overloading and Method Overriding:
- Method overloading allows a class to have multiple methods with the same name but different parameters.
- Method overriding occurs when a subclass provides its own implementation of a method defined in its superclass.
Polymorphism is achieved through method overriding.
Access Modifiers:
Java provides access modifiers to control the visibility and accessibility of classes, methods, and variables. The main access modifiers are public, private, protected, and default (no modifier). They determine where and how the members of a class can be accessed.
Constructors:
Constructors are special methods used to initialize objects. They have the same name as the class and are invoked when an object is created. Constructors can be overloaded to provide different ways of initializing objects.
Packages:
Packages are used to organize classes into namespaces. They provide a way to group related classes, interfaces, and sub-packages together. Packages help avoid naming conflicts and make code organization and management easier.
Remember that this is just a brief overview of OOP in Java. Each of these topics can be explored in much greater detail, but this summary should give you a good starting point.