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 exception handling in java?

570


What are features of java?

559


How big is a 64 bit float?

531


Why should I use abstract class?

562


What is the difference between a vector & an array list?

674






What does sizeof return?

551


What is a hashmap used for?

640


What is the generic function?

524


Is there a jre for java 11?

549


What is finally in Java?

573


What happens when heap memory is full?

523


Explain how to force the garbage collection in java.

527


What is abstraction in java?

613


Why do we use predicate in java?

550


What are the differences between throw and throws?

521