Object as parameters and Returning Objects
๐ท Using Objects as Parameters
✅ Why Use Objects as Parameters?
Passing an object as a parameter allows one class to use the data or behavior of another class.
This supports:
-
Code modularity
-
Encapsulation
-
Code reuse
๐งช Example:
๐ Output:
๐ท Returning Objects from Methods
✅ What is it?
In Java, a method can return an object instead of a primitive type. This allows chaining of object operations and building modular code.
๐งช Example:
๐ Output:
๐ง Summary
Concept | Description |
---|---|
Objects as Parameters | Enables reuse of data and methods of an object in another class |
Returning Objects | Allows method to send back an object for further operations |
Comments
Post a Comment