标签:string main public void 定义 成员 int 关键字 oid
//用class关键字定义一个类,例如: public class Person { //成员变量定义 private int id; private int age = 20; //构造方法 Person(int _id,int _age){ id = _id; age = _age; } //方法定义 public int getAge(){ return age; } public void setAge(int i){ age = i; } public int getId(){ return id; } public void setId(int i){ id = i; } public static void main(String args[]){ /* Person p1 = new Person(); System.out.println("Age="+p1.age); p1.setAge(24); p1.setId(1); System.out.println("Id="+p1.id+"\nAge="+p1.age); */ Person p1 = new Person(1,20); Person p2 = new Person(2,24); System.out.println(p1.getId()+"\t"+p1.getAge()); System.out.println(p2.getId()+"\t"+p2.getAge()); } }
标签:string main public void 定义 成员 int 关键字 oid
原文地址:https://www.cnblogs.com/nyist0/p/12354349.html