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

Can singleton class be inherited in java?

514


Define a java class.

803


Name few "optional" classes introduced with java 8 ?

641


Which programming language is best in future?

519


Can we call virtual funciton in a constructor ?

1771






Are arrays dynamic in java?

530


What is serial version uid and its importance in java?

594


Why is stringbuffer thread safe?

565


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

528


Is java developer a good career?

550


What 5 doubled?

508


How do you remove an element from an arraylist in java?

460


How to access arraylist elements in java?

486


Why can't we override private static methods?

515


what are synchronized methods and synchronized statements? : Java thread

579