1、方法的形参是类名,其实是需要该类的对象
2、方法的返回值是类名,其实是需要返回该类的对象
代码示例
猫类
public class Cat {
public void eat() {
System.out.println("猫吃鱼");
}
}
操作类
public class CatOperate {
public void useCat(Cat c) {//Cat c =new Cat();
c.eat();
}
public Cat getCat(){
Cat c=new Cat();
return c;
}
}
测试类
public class CatDemo {
public static void main(String[] args) {
//创建操作对象并调用方法
CatOperate co = new CatOperate();
Cat c = new Cat();
co.useCat(c);
//两种方法
Cat c2 = co.getCat();//new Cat()
c2.eat();
}
}