Implicit Parameter in Java
What is an Implicit Parameter ?
- The implicit parameter in Java is the object that the method belongs to. It's passed by specifying the reference or variable of the object before the name of the method.
- An implicit parameter is opposite to an explicit parameter, which is passed when specifying the parameter in the parenthesis of a method call.
What is meant by Implicit in Java ?
- Implicit means done by the JVM or the tool , not the Programmer. For Example:Java will provide us default constructor implicitly.
- If the programmer didn't write code for constructor, he can call default constructor. Explicit is opposite to this , ie. programmer has to write .
Explicit Method Example
- When your program calls a method of an object, it's common to pass a value to the method.
- For example, if the object WikitechyEmployee has a method called setJobTitle:
- WikitechyEmployee dave = new WikitechyEmployee();
- dave.setJobTitle("Candlestick Maker");
- The String "Candlestick Maker" is an explicit parameter being passed to the setJobTitle method.
Implicit Method Example
- Here, there is another parameter in the method call that is known as the implicit parameter. The implicit parameter is the object the method belongs to. In the above example, it's dave, the object of type WikitechyEmployee.
- Implicit parameters are not defined within a method declaration because they are implied by the class the method.
- In order to call the setJobTitle method, there must be an object of type WikitechyEmployee.