ساخت یک شیء از یک کلاس درون همان کلاس
پنجشنبه, ۲۰ مرداد ۱۴۰۱، ۱۱:۴۹ ب.ظ
چرا به ساخت یک شیء از یک کلاس درون همان کلاس ممکن است نیاز داشته باشیم؟ نمونه:
class Person { String name; int age; Person mother; Person father; public Person(String name, int age) { this.name = name; this.age = age; } public Person(String name, int age, Person mother, Person father) { this.name = name; this.age = age; this.mother = mother; this.father = father; } } Person p1 = new Person("Son Name", 22, new Person("Mother name"), 45), new Person("Father name"), 50));
۰۱/۰۵/۲۰