-1
Class Person {

  Person name;
  Person age;
  ..
}

In this usage , what does it mean Person name and Person age. Of course name and age data type is Person but I cannot understand the concept how will I use in my program. For example if I Person data type replaced by String name and int age , I will use in main method like:

Person p1 = new Person();
p1.name = "blabla";
p1.age = 30;

But how will we use the Person data type like that. I have already searched on the Internet but I couldn't find anything about that.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

1

This is a bad (catastrophic) design decision.

Instead it should look like

class Person {
    String name;
    int age;
}

There are possibilities when using Person within Person would be justified. Look at the following examples.

class Person {
    Person manager; // Here, an employee could have another Person being its manager
}

class Person {
    Person partner; // Here, a person could be married and have another Person as partner
}
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89