hi i just want to know how my problem that is stated below could be achieved .the example would be lengthy but vey simple . i have three classes mother,father and child
class mother
{
public void eat()
{
System.out.println("eat:Mother's Style");
}
public void play()
{
System.out.println("play:Mother's Style");
}
public void talk()
{
System.out.println("talk:Mother's Style");
}
public void walk()
{
System.out.println("walk:Mother's Style");
}
public void look()
{
System.out.println("look:Mother's Style");
}
}
class father
{
public void eat()
{
System.out.println("eat:father's Style");
}
public void play()
{
System.out.println("play:father's Style");
}
public void talk()
{
System.out.println("talk:father's Style");
}
public void walk()
{
System.out.println("walk:father's Style");
}
public void look()
{
System.out.println("look:father's Style");
}
}
class child inherits both mother and father
{
int eatStyle;
int playStyle;
int walkStyle;
int lookStyle;
int talkStyle;
child(int a,int b,int c,int d,int e)
{
eatStyle = a;
playStyle = b;
walkStyle = c;
lookStyle = d;
talkStyle = e;
}
public void eat()
{
if(eatStyle == 1)
// call father's eat()
else if(eatStyle == 2)
// call mother's eat()
else
// implement his own
}
public void play()
{
if(playStyle == 1)
// call father's play()
else if(playStyle == 2)
// call mother's play()
else
// implement his own
}
public void talk()
{
if(talkStyle == 1)
// call father's talk()
else if(talkStyle == 2)
// call mother's talk()
else
// implement his own
}
public void walk()
{
if(walkStyle == 1)
// call father's walk()
else if(walkStyle == 2)
// call mother's walk()
else
// implement his own
}
public void look()
{
if(lookStyle == 1)
// call father's look()
else if(lookStyle == 2)
// call mother's look()
else
// implement his own
}
}
hi i have a set of classes like described above so if someone creates child sam = new child(1,1,2,3,3)
then "sam" would eat and play like his father and walk like his mother and others he does in his unique way.
but since
java doesnt have multiple inheritance how can this be implemented . argumnets suggests that multiple inheritance is complex and confusing . but this is a obvious case in the real world .but how this can be achieved. this question was in my mind right from the day i studied inheritance in java.
expecting the answer
thanks and regards
ashok
thanks and regards
ashok