Does constructor return any value in Java?


No, constructor does not return any value.

  • While declaring a constructor you will not have anything like return type.
  • In general, Constructor is implicitly called at the time of instantiation.
  • And it is not a method, its sole purpose is to initialize the instance variables.

Example

Live Demo

public class Sample{
   public Sample(){
      System.out.println("This is a constructor");
   }
   public static void main(String args[]){
      Sample obj = new Sample();
   }
}

Output

This is a constructor

mkotla
mkotla

e

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements