形参和返回值

类名作为形参and类名作为方法的返回值

1)类名作为形参
类名作为形参实际上要的是----该类的对象。
(2)类名作为方法的返回值
类名作为方法的返回值实际上返回的是—该类的对象

class Teacher{
	//Student类名作为show方法的形式参数
	void show(Student s){
		s.study();
	}
	
	//类名作为方法的返回值
	Student getStudent(){
		Student s=new Student();//Student类实例化
		return s;
	}
}

class Student{
	String name;
	int age;
	void study(){
		System.out.println("I can study");
	}
}

class Demo1{
	public static void main(String[] args){
		Teacher t= new Teacher();
		Student s= new Student();
		t.show(s);//输出I can study
		System.out.println(t.getStudent());//输出对象的地址值	
	}
}

 

 

 

 

 

posted @ 2019-08-23 20:09  水果、、  阅读(391)  评论(0编辑  收藏  举报