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

How will you get the platform dependent values like line separator, path separator, etc., ?

592


Explain the reason behind ending a program with a system.exit(0)?

608


State two differences between C and Java.

699


Is object a data type?

565


What is the difference between jdk and jre?

614






What is a boolean output?

532


What are generic methods?

539


what is instanceof operator used in java?

597


What happens to a static var that is defined within a method of a class?

558


Difference between throw and throws?

629


Which method you will use to create a new file to store some log data. Each time a new log entry is necessary, write string to the file in java ?

640


Explain the difference between protected and default access.

525


What one should take care of, while serializing the object?

490


Difference between association, composition and aggregation?

566


What is static class

624