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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you make sure that your singleton class will always return single instance in multi-threaded environment?

799


What do you mean by chromounits in java8?

732


If two threads have same priority which thread will be executed first ?

1166


What is the difference between final, finally and finalize() in java?

809


What is the benefit of abstract class?

724


What is the difference between the boolean & operator and the && operator in java programming?

792


How many ways can we create the string object?

793


What is a parameter in matrices?

773


Define "Access specifiers" in java.

952


How to create a custom exception?

765


Explain OOPs concept.

858


Can we create an object of private class?

757


Can we override private method?

831


How will you print number in reverse (descending) order in BST.

782


What are the types of sockets in java?

769