3. Consider the following cl- definition and output the resu public class Children (String name; int friends; public Children(String name) (this.name = name; friends = 0; } public void getFriend(Children k) (friends++; } public int numFriends() { return friends; } public String playsalong() Lreturn "joy"; } public String toString() Lreturn "a child named "+name;} }
3. Consider the following cl- definition and output the resu public class Children (String name; int friends; public Children(String name) (this.name = name; friends = 0; } public void getFriend(Children k) (friends++; } public int numFriends() { return friends; } public String playsalong() Lreturn "joy"; } public String toString() Lreturn "a child named "+name;} }
Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 16RQ
Related questions
Question
100%
![3. Consider the following class definition and write an appropriate Java program according to the
definition and output the result.
public class Girl extends
public class Children
(String name;
int friends;
public Children(String name)
{this.name = name;
friends = 0;
}
public class Boy extends
Children
Children
{public Girl(String name)
(super(name);
friends = 1;
}
public void
getFriend(Children k)
{if (k instanceof Girl)
{public Boy(String name)
{super(name); }
public String playsalong( )
{return (super.playsWith()
+ "block");
public void
getFriend(Children k)
{friends++; }
public int numFriends() {
return friends; }
public String toString()
{return "a boy named " +
name; }
}
friends += k.numFriends( );
else
public String playsalong()
{return "joy"; }
public String toString()
Lreturn "a child named
"+name;}
friends++;
}
public String toString()
Lreturn "a girl named "+
name;}
}
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F92c8b241-fb10-4bf6-9986-2661cf4ba619%2Fb7c66a16-2706-4c44-a991-dfaca7a9e43d%2Ftktmzg_processed.png&w=3840&q=75)
Transcribed Image Text:3. Consider the following class definition and write an appropriate Java program according to the
definition and output the result.
public class Girl extends
public class Children
(String name;
int friends;
public Children(String name)
{this.name = name;
friends = 0;
}
public class Boy extends
Children
Children
{public Girl(String name)
(super(name);
friends = 1;
}
public void
getFriend(Children k)
{if (k instanceof Girl)
{public Boy(String name)
{super(name); }
public String playsalong( )
{return (super.playsWith()
+ "block");
public void
getFriend(Children k)
{friends++; }
public int numFriends() {
return friends; }
public String toString()
{return "a boy named " +
name; }
}
friends += k.numFriends( );
else
public String playsalong()
{return "joy"; }
public String toString()
Lreturn "a child named
"+name;}
friends++;
}
public String toString()
Lreturn "a girl named "+
name;}
}
}
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage