WHAT IS THE DIFFERENCE BETWEEN CONSTRUCTOR AND METHOD?

Pushpendra Singh

Total Post:240

Points:1200
Posted by  Pushpendra Singh
Java 
 1086  View(s)
Ratings:
Rate this:
  1. Pushpendra Singh

    Post:240

    Points:1200
    What is the difference between constructor and method?

    A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.

    A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.
    Constructor does not have a return type.
    Name of constructor is the same as that of class in which it is declared.


    public class ClassA {
    public ClassA()
    {
    // Initilize code in the constructor.
    }
    }

      Modified On Mar-26-2018 05:08:07 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!