It was for one interview last week, I asked the prospect a very simple question. How to identify a function, a method and a property.
The answer I expected was very simple one which a newcomer should be able to get the trick. He started narrating a long story and finally connected all the above three someway.
But there is a simple way to explain the same.
Function()
A function has parentheses after its name and does not have a dot on the left side.
&Object.Method()
A method has parentheses after its name and has a dot on the left side.
&Object.Property
A property has a dot on its left and no parentheses on the right.
Pretty simple and easy to understand right :)
The answer I expected was very simple one which a newcomer should be able to get the trick. He started narrating a long story and finally connected all the above three someway.
But there is a simple way to explain the same.
Function()
A function has parentheses after its name and does not have a dot on the left side.
&Object.Method()
A method has parentheses after its name and has a dot on the left side.
&Object.Property
A property has a dot on its left and no parentheses on the right.
Pretty simple and easy to understand right :)
Function is independent of a class, a stand alone sub routine.
ReplyDeleteMethod is a part of the class and can is available for use only by its objects or objects derived from it.
Property is an attribute of the class.
Thanks Ram :)
ReplyDelete