Search This Blog

Wednesday, May 4, 2011

Function, Method & Property

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 :)

2 comments:

  1. Function is independent of a class, a stand alone sub routine.

    Method 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.

    ReplyDelete