Introduction
Constructors are a special type of function in which the name is the same as the class name. And it is automatically invoked (called) when the object of the class is creative. The constructor has the following features.
- Constructor name must have a class name
- Constructor has no return type even “void”.
- We cannot call constructor explicitly
- Constructor can be overloaded
- Constructor cannot be inherited
- We cannot make constructor private
There are four types of constructors in JAVA.
- Default constructor (make java)
- Non parameterize / normal constructor.
- Parameterize constructor
- Copy constructor
Default Constructor
- Class A {}

Non – Parameterized Constructor
We can make our own constructor without any parameter. The main purpose of constructors is to provide a default value in a variable and perform some startup code.
- class A {
- inti = 100;
- A() {
- i = 200;
- }
- void show() {
- System.out.print(i)
- }
- }
- class B {
- public static void main(String...args) {
- A ob = new A();
- ob.show();
- }
- }
Parameterized Constructor
Example
- class A {
- A(inti) {
- System.out.print(i)
- }
- void show() {
- System.out.print("Hello Parametrized Constructor")
- }
- }
- class B {
- public static void main(String...args) {
- inti = 20;
- A ob = new A(i);
- ob.show();
- }
- }
Note
Copy Constructor:
Example:
- class A {
- int n1, n2;
- A(inti, int j) {
- n1 = i;
- n2 = j;
- }
- A(A ref) {
- n1 = ref.n1;
- n2 = ref.n2;
- }
- void show() {
- System.out.print(n1);
- System.out.print(n2);
- }
- }
- class B {
- public static void main(String...args) {
- A ob1 = new A(10, 20);
- ob1.show();
- A ob2 = new A(ob1);
- ob2.show();
- }
- }

Dharmesh SinghPosted Apr 27, 2016, 9:14 PM
http://www.c-sharpcorner.com/article/most-popular-programming-language-of-2016/
Dharmesh SinghPosted Apr 27, 2016, 9:13 PM
yes java is a useful Language. Java
Meera SharmaPosted Apr 27, 2016, 1:03 PM
is java a useful language nowadays...