What is a Constructor?

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.

Constructor Example

This example 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.



Top 5 Free Networking Tools

Bookmark What is a Constructor?

Latest Blog Posts


English English GermanGerman SpanishSpanish FrenchFrench ItalianItalian PortuguesePortuguese RussianRussian DutchDutch
GreekGreek HindiHindi JapaneseJapanese KoreanKorean ChineseChinese Chinese (Simplified)Chinese (Simplified) ArabicArabic

Copyright 2009 Tech-FAQ. All rights reserved. Privacy Policy.