문제

In System.out.println, println is a accessor or mutator method in JAVA ?

Thank you....

도움이 되었습니까?

해결책

I would say it's neither. It only exists for its side effects; it is not obliged to do anything at all to the internal state of System.out (which is what accessors and mutators are about).

다른 팁

It's not an accessor, because it doesn't return a value (it's void). One could argue that it's a mutator, because it modifies the state of the underlying I/O system (it has side effects), but it's not a clear-cut distinction, because is not modifying the state of the System class or any of its instances.

The accessor/mutator distinction generally applies to methods that return a value obtained from an object's attributes (accessors) or methods that modify those attributes (mutators), but this is not the case for println(), the state being modified (an output stream) lies outside of the class.

No. Accessors are "getXXX", mutators are "setXXX". println is neither.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top