প্রতিটি ক্লাস অবজেক্ট একই new কীওয়ার্ড ব্যবহার করে তৈরি হয়, তাই অবজেক্টটি কোন ক্লাসের জন্য তৈরি হবে সে তথ্য থাকতে হয়। এই কারণেই কনস্ট্রাক্টরের নাম ক্লাসের নামের সাথে একই হতে হয়।
উদাহরণ
class MyConstructor {
public MyConstructor() {
System.out.println("The constructor name should be same as the class name");
}
public static void main(String args[]) {
MyConstructor mc = new MyConstructor();
}
}
উপরোক্ত প্রোগ্রামে কনস্ট্রাক্টরের নাম ক্লাসের নামের সাথে একই (MyConstructor)।
আউটপুট
The constructor name should be same as the class name