Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Here is the appropriate Java program according to the given class definitions java class Children St...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
66430f9d8bd14_952650.pdf
180 KBs PDF File
66430f9d8bd14_952650.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started