标签:ring private system.in lips port work 年龄 blog ram
新建包com.helloworld,添加类/hello/src/com/helloworld/hello.java
package com.helloworld; import com.model.*; public class hello { public static void main(String[] args) { person p1= new person(); //System.in p1.setName("aaa"); p1.setAge(10); System.out.print("myeclipse你好, 我叫"+p1.getName()+",今年"+p1.getAge()+"岁\r\n"); p1.work(); lalala(p1); System.out.print("myeclipse你好, 我叫"+p1.getName()+",今年"+p1.getAge()+"岁\r\n"); p1.work(); int i1=10; System.out.print(i1+"\r\n"); yayaya(i1); System.out.print(i1+"\r\n"); } public static void lalala(person p2) { p2.setName("bbbb"); } public static void yayaya(int ii) { ii=ii+1; } }
新建包com.model,添加一个类/hello/src/com/model/person.java
package com.model; public class person { private String name;// 姓名 private int age;// 年龄 /** * @return name */ public String getName() { return name; } /** * @param name * 要设置的 name */ public void setName(String name) { this.name = name; } /** * @return age */ public int getAge() { return age; } /** * @param age * 要设置的 age */ public void setAge(int age) { this.age = age; } public void work() { System.out.print(name + "加班呢~~~~~~~~~~~~~~~~\r\n"); } }
输出
myeclipse你好, 我叫aaa,今年10岁
aaa加班呢~~~~~~~~~~~~~~~~
myeclipse你好, 我叫bbbb,今年10岁
bbbb加班呢~~~~~~~~~~~~~~~~
10
10
==========================
与.net一样,类是引用传递
标签:ring private system.in lips port work 年龄 blog ram
原文地址:http://www.cnblogs.com/wangyinlon/p/7677645.html