Answered step by step
Verified Expert Solution
Link Copied!

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Document Format ( 2 attachments)

PDF file Icon
66430f9d8bd14_952650.pdf

180 KBs PDF File

Word file Icon
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

Recommended Textbook for

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions

Question

=+b) What is the maximax choice? Section 23.4

Answered: 1 week ago

Question

6. Use the results of Probs. 4 and 5 to demonstrate Theorem 5.2.5.

Answered: 1 week ago

Question

4. In Prob. 1, find the dimension of S S.

Answered: 1 week ago