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 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
Here is the appropriate Java program according to the given class definitions java class Children St... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
66430f9d8bd14_952650.pdf
180 KBs PDF File
66430f9d8bd14_952650.docx
120 KBs Word File
