Java is
OOP[
^] language and therefore you can use
inheritance, polymorphism[
^], etc.
An example from above link:
class Teacher {
String designation = "Teacher";
String collegeName = "Beginnersbook";
void does(){
System.out.println("Teaching");
}
}
public class PhysicsTeacher extends Teacher{
String mainSubject = "Physics";
public static void main(String args[]){
PhysicsTeacher obj = new PhysicsTeacher();
System.out.println(obj.collegeName);
System.out.println(obj.designation);
System.out.println(obj.mainSubject);
obj.does();
}
}
On the same manner, you can extend
Person
class by creating
Man
and
Woman
classes which derived from
Person
.
As to this statement:
Quote:
i wanted to create a class called "theirdetails" where i am going to insert data like
int theDayTheyMet
and
int ageDifference
or String
theirNamesTogether
You can always create a
Couple
or
Pair
class which may hold 2 public members:
Man
and
Woman
.
class Couple {
private Man his = new Man(...);
private Woman her = new Woman(...);
}
Because
Man
and
Woman
base class is
Person
, you can simplify your
Couple
class to:
class Couple {
private List<Person> persons = new ArrayList<Person>();
}
A
List[
^] and an
ArrayList[
^] provide several methods to add/iterate/remove elements.
[EDIT]
I'd store
date[
^] of birth instead of age. You can calculate age this way:
year_of_current_date - year_of_birth
.
See:
Calculate Age from date of birth in Java - Memorynotfound[
^]
date - How do I calculate someone's age in Java?[
^]