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

Do you know why doesn't the java library use a randomized version of quicksort?

552


What is meant by oops concept in java?

502


What is class level lock ?

608


What is the reason behind using constructors and destructors?

553


What is classes in java?

515






Explain what is Marker interface?

613


How does remove work in java?

517


Variable of the boolean type is automatically initialized as?

593


What are serialization and deserialization?

723


What is the use of using enum to declare a constant?

555


What is the difference between compile-time polymorphism and runtime polymorphism?

558


What are the four integer types supported by java?

558


What is math floor in java?

470


In a container there are 5 components. I want to display all the component names, how will you do that?

1557


What is keyword in oop?

516