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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between scrollbar and scrollpane?

607


What are the two parts of a conditional statement?

508


Can we increase array size dynamically in java?

500


What are the important features of Java 11 release?

576


which class is the wait() method defined in? : Java thread

519






Can we write any code after throw statement?

599


When should the method invokelater() be used?

580


Why does java have two ways to create child threads? Which way is better?

540


What is mutable object and immutable object?

624


Explain the concept of proper inheritance?

613


Can we create a class inside a class in java?

540


Explain the importance of join() method in thread class?

636


Is char a data type in java?

537


How are multiple inheritances done in Java?

616


Justify your answer that you can't define a method inside another method in java, if you can then how?

600