jump to navigation

Difference between a constructor and a method November 19, 2006

Posted by Allu in JAVA.
trackback

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.

Comments»

1. manohar - June 8, 2008

the terminology is quite easy to understand.i make sure to approach this site whenever i come across a problem.

2. bangarraju - September 14, 2008

i want to know about interfaces. how interfaces are different from abstract classes? please explain me

thank you

chandan kumar - May 12, 2011

abstract class may define some method and may contain all method abstract but interface can not define any method, it only contain abstract method.

Archana - September 24, 2012

Interfaces enable you to implement multiple inheritance but oly one class can be inherited by abstract class.
Interface consists of methods only whereas abstract class contains attributes ad methods.
Abstract class is used in the same package whereas interfaces can be realised across multiple packages.

3. Utkarsh - March 25, 2010

differences are all very good, but what is the similiarity?

4. bhanuchander - August 17, 2010

though the difference is good y cant we use only constructors instead of methods .which will be very easy for us to handle

5. Tejashri - October 3, 2010

What is the use of bin and lib in jdk?

lakshmi narayana - October 23, 2010

Bin contains all tools such as javac,appletviewer,awt tool etc where as lib contains API and all packages

6. regitha - January 28, 2012

yes now i understand this difference

7. balaji - February 15, 2012

Interface:
If u declare one class as a interface , inside the interface we should give the signature for the method… no need to give the definition.
If u extend the interface we should give the definition for the method.
Abstract:
In ur extended sub class u forgot to give the definition for the method.then u should eclare ur superclass as a abstrasct class…..

8. samee - March 27, 2012

what is the properaties of using keyword ( this) in the cinstractor

9. Shrikanth Gopinath - May 29, 2012

Default access specifier for Constructor is public and method is private. Constructor should have same name as Class name. Constructor can be overloaded like methods.

10. zeenat - June 20, 2012

can any 1 help in java programs???

11. KEITH - September 28, 2012

thanks

12. renubala - February 11, 2013

best bt can’t given any exp..for this

13. Mayank goyal - April 11, 2013

Abstract class- it contains concrete and abstract methods.if there is 1 number of method is abstract then the class should be defined as a abstract class. else if there is no any abstract method then its not mandatory to defined class as a abstract class

Interface-by default all the methods public or abstract .there is no need to define the method abstract. and in the case of interface we can implement more than 1 class

14. Drojet Jaypizzy - November 6, 2013

thanks for all this


Leave a reply to Archana Cancel reply