Home > Back-end >  Write a Java application as required
Write a Java application as required

Time:09-23

1, implement a Cat (Cat), define "varieties (name)", "age (age)," "feature (pro)" three variables, set the three information of object, getAllInfo () to display all information,
2, the interface implementation of polymorphic: Animal interface, two abstract methods: call cry () and eat eat (), class implements the interface,

CodePudding user response:

Is this job?

CodePudding user response:

Public class car {
private String name;//private variable
Private String age;
Private String pro;
Public String getName () {//remove the variable
return name; }
Public void elegantly-named setName (String n)
{name=n; }
Public String getAge () {
Return the age; }
Public String getPro () {
Return pro;

}
Public void getAllInfo () {
System. The out. Println (" name "+ name);
}
Public static void main (String arges []) {
The car c=new car ();
C.n ame="pear flower";
C.g etAllInfo ();

}
}
Interface cat {
Void the eat ();
Void cry ();
Maybe have wrong please correct me

CodePudding user response:

Yes, but I can't
  • Related