Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > Javascript

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 03-28-2016, 02:40 AM   #1
chinmay.sahoo
Registered User
 
Join Date: Dec 2013
Location: Banglore
Posts: 335
Send a message via AIM to chinmay.sahoo Send a message via MSN to chinmay.sahoo
Arrow What is the difference between a constructor and a method?

A constructor is member function and it is used to create object of the class. It assigns the same name as that in the class, and has no return type. Whereas method is a ordinary member function, which has own name and return type. They are invoked using dot operator.











Hair Building Fiber | Growth on Height
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
chinmay.sahoo is offline   Reply With Quote

Old 05-06-2016, 01:26 AM   #2
Kunal
Registered User
 
Join Date: Feb 2016
Posts: 81
A constructor is a method inside a class that is invoked every time you run your program.
A method is a set of instructions (a function) that is run within your class.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Kunal is offline   Reply With Quote
Old 11-17-2016, 01:54 AM   #3
neha kumari
Registered User
 
Join Date: Oct 2016
Posts: 42
Constructor are used to initialize the state of object,where as method is expose the behaviour of object.Constructor must not have return type where as method must have return type.Constructor name same as the class name where as method may or may not the same class name.

Wooden Pen Drive | Promotional Power Bank
neha kumari is offline   Reply With Quote
Old 01-25-2017, 10:26 PM   #4
Claire_Anderson
Registered User
 
Join Date: Aug 2016
Posts: 49
1. Constructors are used to allocate memory or they are used to initialize the state of object,where as method is expose the behavior of object.
2. Constructor must not have return type where as method must have return type.
3. Constructor name same as the class name where as method may or may not the same class name
__________________
Claire

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Claire_Anderson is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:25 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.