Java Programming Tutorial - 17 - Constructors

A constructor is a method that creates and returns an instance (object) of the class.



// Constructors Sample Code
import java.awt.*;

class Circle {
Color c;
int r;

public Circle() {
c=Color.blue;
r=25;
}

public static void main(String[] args) {
Circle circ = new Circle();
}

}

0 comments:

Post a Comment