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 ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe different states of a thread.

773


Give a practical example of singleton class usage?

777


When can you say a graph to be a tree?

841


When will you define a method as static?

796


Explain about arraylist?

772


What are sets in java?

726


Explain public static void main(string args[]).

852


What is the difference between final, finally and finalize() in java?

783


What do you mean by local variable and instance variable?

715


What is return in java?

740


What is a local, member and a class variable?

778


What are the core java topics?

785


What are keywords in java?

765


What is thread safe in java?

732


How can you make a class serializable in java?

774