Question: 3. Consider the following class definition and write an appropriate Java program according to the definition and output the result. public class Children [String

3. Consider the following class definition and write an appropriate Java program

3. Consider the following class definition and write an appropriate Java program according to the definition and output the result. public class Children [String name; int friends; public Children(String name) [this name name; friends =Q; } public void getfriend(Children k) {friends++; } public int numFriends!) { return friends; } public String playsalone() {return "joy"; } public String toString() return "a child named "+name;} } public class Girl extends Children public Girl(String name) (super(name); friends =1 } public void getFriend(Children k) Lif (k instanceof Girl) else public class Boy extends Children public Boy(String name) super(name); } public String playsalone! return (super playsWith() + "block" } public String toString!) return "a boy named " + friends +=kpumFriends(); name } friends++; } public String toString!! return "a girl named "+ name;} } [10 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is the appropriate Java program according to the given class definitions java class Children St... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

66430f9d8bd14_952650.pdf

180 KBs PDF File

Word file Icon

66430f9d8bd14_952650.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!