关于类与对象
public class ClassHomework {
public static void main(String[] args) {
Cat a= new Cat();
String str=a.getold(19);//getold方法return出来后赋值给b
System.out.println(str);
a.speak();
}
}
class Cat {
int age;
String kind;
String name;
public void speak(){
System.out.println("汪汪...");
}
public String getold(int age){
String str;
if(age<=5)
str="这只狗的年龄是"+age+",这是只年轻的狗";
else
str="这只狗的年龄是"+age+",这是只年老的狗";
return str;
}
}
class dog{
public static void add() {
Cat d = new Cat();
String v=d.getold(1);
System.out.println(v);
}
}