46 面向对象方法的形式参数是类名的时候如何调用

 1 class Dem1_Student{
 2     public static void main(String[] args) {
 3         print(10);  //基本数据类型当作形式参数 
 4 
 5         Student s = new Student();
 6         print(s);  // 引用数据类型当作形式参数,需要传入一个地址   stu s 指向同一对象
 7 
 8     }
 9 
10     public static void print(int x){
11         System.out.println(x);
12     }
13 
14 
15     public static void print(Student stu){
16         stu.name = "pan";
17         stu.age = 20;
18         stu.study();
19     }
20 }// 测试类
21 
22 class Student{
23 
24     String name;
25     int age;
26 
27 
28     public void study(){
29         System.out.println("study....s");
30     }
31 
32 
33 
34 }   //基本类

 

posted @ 2017-01-24 22:37  panw3i  阅读(94)  评论(0编辑  收藏  举报