Differentiate constructor and a method and how are it be
used?

Answer Posted / kabita

constructor & methods are both member functions of a class.
when an object is created the constructor is invoked
automatically,bt we have to call the methods explicitly
through objectname.
methods have returntype ,bt constructors haven't.
constructors must have same name as class name bt methods
have not.
constructors are used for initialization of
objects,variables.

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List some oops concepts in java?

586


Why is String immutable?

626


what is the difference between yielding and sleeping? : Java thread

525


Is .net better than java?

557


Is null a keyword in java?

559






Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

594


Outline the major features of java.

567


what is the purpose of the runtime class?

555


What is package private scope in java?

538


Can you make a constructor final?

584


What is array length?

509


What is map java?

521


What is string array?

584


When is the garbage collection used in Java?

658


Should database connections be singleton?

570