Java – More about method

Java – More about method 2017-08-09T10:54:34+00:00

1. Passing Objects as a Parameter to Method.

We have seen that methods can take parameters as input and process them.

It is also common to pass objects as a parameter to methods.


Output :
Multiplication is 30
2. Method overloading with object as a parameter.


Output :
There is nothing to multiply
n1 = 5 n2 = 6
Multiplication of two objects
n1 = 30 n2 = 30
3. Return an Object.
A method can return any type of data, including class type (object) that you create.


Output :
An Example of returning an Object
n1 = 30 n2 = 30
RetObj multiply(RetObj p1, RetObj p2) This is the syntax in our program which has return type object.
obj3 = obj3.multiply(obj1, obj2); this is the syntax which calls method multiply and return object, it will store in obj3.

Prev Next