Back to Top

Sunday, 15 January 2012

JAVA : What is the difference between a constructor and a method?

  A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.

  A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

3 Responses to “ JAVA : What is the difference between a constructor and a method? ”

jitendrakumar pandey said...
8 September 2013 at 18:18

Constructor must have same name as Class name.
Constructor does not have return type not even void.
Constructor does not support inheritance.
Constructor does not support overriding concept.
No need to call constructor explicitly it is called automatically at the time of object creation.
Generally we need constructor to write initialization logic.not business logic.
if we didn't provide constructor then JVM automatically add default constructor.
Method can have any name.
Method can have any return type.
We write method for modular programming.
In Program when repetitive statement occurred better to go for method.
it can be used to write business logic.
Need explicit calling by using object or Class name.

Naviya Nair said...
24 October 2016 at 15:10

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai

raghu konda said...
28 September 2017 at 10:14

Excellent…Amazing…. I’m satisfied to find so many helpful information here within the put up,for latest php jobs in hyderabad. we want work out extra strategies in this regard, thanks for sharing.

Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs