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 is classes in java?

713


Define a package.

778


Where is singleton pattern used?

751


Can we override constructor?

780


What are variable names?

724


Tell me how many ways are there to initialise an integer with a constant.

879


What is %d in printf?

753


How many bytes is a unicode character?

737


Is string is a keyword in java?

749


Is java based on c?

758


What is exception in java?

756


What is the final access modifier in java?

822


What is double in java?

738


Is it possible for yielded thread to get chance for its execution again ?

781


What is indexof?

734