Click Here for 3 Month Free of ASP.NET Hosting!
Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » OOP » OOP
What is the difference between constructor and method?
Posted by praveen Feb 14, 2007
Viewed : 6272 times
Major Category : OOP
Minor Category : Others
Total Replies : 9
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
Shaik Hanumantha Rao
Sep 19, 2007

a constructor is a method in the class which gets executed when its object is created. Usually, we put the initialization code in the constructor. Writing a constructor in the class is damn simple, have a look at the following sample:

public class Test

{

    public Test()

    {

        //Initilize code in the constructor.
    }
}

 

  • Constructors doesn't returns any value.
  • References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.
  • Constructors cannot be declared with the keyword virtual.
  • If the constructors is defined as private, we can not create instance of that class.

 

Method:

  •  In methods we can define variables.These variables scope is within methods only.
  • If you declare a public variable , it will be accessed in all mehtods.
  • Methods may/maynot contains return type.
  • Methods could be inhereted in derived class(Note That mehtod should be Public)

 

Ashish Y
Jun 11, 2007
  1. constuctor is a method of name ""same of class"" and is automatically called when the object of that class is created.
  2. The methods aren't called when object is created,We have to call by using its class name.

Mar 08, 2007
select * from

Mar 08, 2007
by default constructor's return type is that of a class in which it is defined so no need to write explicitly the return type. [don't know if u know c or not, if yes then it is mallock type casted to the pointer of that class type] a method must[not can...., as even if it returns nothing it should have a return type of VOID] have a return type. just as methods constructors can be public,private,static etc. but as a general guideline it is advisable to have constructors public. constructor anme should be exactly[case sensitive] same as the calss name last but not the least even if u dont define a default constructor then when you instanciate an object ...it is the system who defines one for you and calls it in order to create an instance of object... Regards Sam
Srikanth chennu
Feb 20, 2007

Constructor is used to create an instance of  object.

Method is used to perform some operations.

 

 

SUJITKUMAR PATIL
Feb 14, 2007
->constructor call automatically . constructor is also public or private. constructor is for memory management ->method call forcefully . method only focus on functionality
praveen
Feb 14, 2007

1. constructor name should match with a class name, but for a method a name could be of anything.

2.constructor don't have any return type, where as a method can have a return type. 

  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved