OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 2 : Topic - 15 : Nesting of Methods in Java
Unit - 2
Topic - 15 : Nesting of Methods in Java
In Java, normally a method of a class is called using an object of that class with the dot (.
) operator.
However, if one method of a class calls another method from the same class, we don’t need to use an object — we can call it directly by name.
This concept is called Nesting of Methods.
Example Program
Output
Explanation
-
The method
display()
callsgreatest()
directly (without using an object). -
Both methods belong to the same class (
Test
), so we can use the method name directly. -
This avoids repetitive object references when calling methods inside the same class.
Comments
Post a Comment