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
icon
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;}
}
}
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage