QUESTION: Why I can't run this coding? . import java.util.*; 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(){ return "joy"; } public String toString(){ return "a child named "+name;} } class Girl extends Children { public Girl(String name){ super(name); friends = 1; } public void getFriend(Children k){ if (k instanceof Girl) friends += k.numFriends( ); else friends++; } public String toString( ){ return "a girl named "+ name;} } class Boy extends Children { public Boy(String name){ super(name); } public String toString(){ return "a boy named " +name; } }
QUESTION: Why I can't run this coding?
.
import java.util.*;
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(){
return "joy";
}
public String toString(){
return "a child named "+name;}
}
class Girl extends Children
{
public Girl(String name){
super(name);
friends = 1;
}
public void getFriend(Children k){
if (k instanceof Girl)
friends += k.numFriends( );
else
friends++;
}
public String toString( ){
return "a girl named "+ name;}
}
class Boy extends Children
{
public Boy(String name){
super(name);
}
public String toString(){
return "a boy named " +name; }
}
Step by step
Solved in 2 steps