Java Constructor

  • Constructor is a special method.
  • Constructor name and the class name must be same.
  • Constructor never returns any value.
  • Constructor is specifically used to initialize data or objects.
  • Constructor executes automatically when an object is created, which is the main advantage.
  • If a program having no constructor, then at the time of compilation, the compiler provides a default constructor.

 

 

Example:

class A {
    int x;
    at the compile time =>  class A {
            inr x;
            -- --A() {}
        }
        -- -- --
}

 

 

 

There are 2 types of constructors, like 0-arg constructor and n-arg constructor(parameterized constructor).

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment