Property acts as a cross link between the field and the method . Actually it behaves as a field. We can retrieve and store data from the field using property.
The compiler automatically translates the field like property into a call like special method called as 'accessor" . In property there are two accessor and that are used to save value and retrieve value from the field. The two properties are 'get' and 'set'.
The get property is used to retrieve a value from the field and the set property is used to assign a value to a field .
Depending on there use properties are categorised into three types,
ReadWrite Property :- When both get and set properties are present it is called as ReadWrite Property.
ReadOnly Property :- When there is only get accessor it is called as ReadOnly Property.
WriteOnly Property :- When there is only set accessor, it is called as WriteOnly Property.
Asked In: Many Interviews |