Yes it will. When a method performs an operation using the reference in this.driver
, it will be performing an operation on the same WebDriver
that you passed to the constructor. If that method modifies the state of the object ... it is the object that you passed in that is being modified.
- Java call semantics are "call by value" aka "pass by value"
- When you pass an object, the value you are passing is the reference to the object.
- Java doesn't make copies of objects implicitly.
In your example code in the question, you are not actually modifying the object that you passed to the constructor. (But you certainly could ...)
If you don't what the constructor (or some other method of the class) to be able to modify the object passed to it, you could:
- pass it an immutable object, or
- pass it a copy (or clone) of the original object.