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

Answer Posted / vishwanath

mainly there are
i.constructor name is same as the class name whereas method name doesn't.
ii.constructor is implicitly called when an object is created.....but the method is explicitly called by using object.
iii.constructor has no return type hence it doesn't return anything.....but method has return type.
iv.constructor is used to create and initialize data members.....where as method is created to code the specific task.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the loops in java?

777


Is arraylist ordered in java?

805


What is public static?

774


Can you declare a private method as static?

936


What is foreach loop in java?

778


What is an exception in java?

902


What is multithreading and its advantages?

835


What is the static variable?

830


What is the equal sign?

827


What is Mutex (Mutual Exclusion Object) ?

875


What is synchronization and why is it important in java programming?

725


What is the difference between serializable and externalizable interfaces?

822


What do you mean by order of precedence and associativity?

751


What is t in generics in java?

829


How can you add and remove nodes in jtree?

831