|
A constructor is a special method for initializing a new instance of a class.
The constructor method for a class will have the same name as the class.
The example below shows a class and a constructor named Circle:
public class Circle {
public int x = 0;
public int y = 0;
public int radius = 0;
public Circle(int x, int y, int radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
}
|
A class may have multiple constructors. In this case, each constructor will have the same name, but will have different arguments.
A no-argument constructor is a constructor which does not take any arguments.
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.