You are on page 1of 6

Object Oriented Programming II

JAVA
Call by Value
• There is only call by value in java, not call by
reference. If we call a method passing a value,
it is known as call by value. The changes being
done in the called method, is not affected in
the calling method.
Example Code
• In case of call by value original value is not changed. Let's take
a simple example:
Call by Reference (passing object)
• In case of call by reference original value is
changed if we made changes in the called
method. If we pass object in place of any
value, original value will be changed.
Example Code
• In this example we are passing object as a value.
Constructor Exercise
• You have a class named as Geometry. Inside the
class, create 3 constructors.
- First constructor will calculate the area of a
Triangle (Formula: Area=1/2 * (base * height))
- Second constructor will calculate the area of a
Circle (Formula: Area = π r2 )
- Third constructor will calculate the area of a
Trapezium (Formula: Area = ½ (a + b)h )
 Now write down the code for Geometry class
using Constructor Overloading concept.

You might also like