What is constructor? give an example

A constructor is a special method for initializing a new instance of a class
The constructor method is same name as the class name.A class have more than one constructor.
In this case each constructor have same name but different Parameters.

Example:-


public class A
{
public int x = 0
public int y = 0
public int radius = 0

public A(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
}



1)Copy Construtor
2)paramiterised constructor
3)Dummy constructor
4)Dynamic constructor

No comments:

Post a Comment

Plz Share your comments...