Differentiate constructor and a method and how are it be
used?

Answer Posted / pranab dutta

A constructor is a member function of a class that is used
to create objects of that class where as a method is an
ordinary member function of a class.
Constructor has the same name as the class itself and
Member has its own name.
A Constructor has no return type, and is invoked using the
new operator.. Whereas a Member has a return type (which
may be void), and is invoked using the dot operator.

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what happens when a thread cannot acquire a lock on an object? : Java thread

536


What is default switch case? Give example.

574


Can a final variable be null?

541


Can we have more than one package statement in the source file?

639


What is overloading and overriding in java?

656






What do you understand by weak reference?

550


What are data structures in java?

527


What is a line break?

580


How many types of keywords are there?

561


What is the difference between serializable and externalizable interface?

566


Can a private method be declared as static?

579


What is api data?

530


What value is a variable of the string type automatically initialized?

609


Can we have two main methods in a java class?

534


What is the difference between a local variable and an instance variable?

544