Type Here to Get Search Results !

In OOP, what is a "getter" method?

0

 In OOP, what is a "getter" method?

A) A method that sets the value of a private variable.
B) A method that retrieves the value of a private variable.
C) A method that performs calculations.
D) A method that deletes an object.

Answer: B) A method that retrieves the value of a private variable.

Explanation: A "getter" method, also known as an accessor method, is used to read or retrieve the value of a private instance variable. This adheres to the principle of encapsulation, as it allows controlled access to the internal state of an object without exposing it directly.

Post a Comment

0 Comments