Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

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).

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext