Welcome 微信登录

首页 / 软件开发 / JAVA / Java语言入门教程(一):Java类的组成

Java语言入门教程(一):Java类的组成2011-03-25taomoon719的专栏一直很喜欢一句广告词:生活就是一个七天又一个七天。而我想说的是,Java应用就 是一个类又一个类。Java是面向对象的语言,对象都是由类实例化而来。一个Java应用, 不论简单还是复杂,都是由若干个Java类组成的。因此,对于初学者,先了解Java类的组 成是必要的。

Java类的组成主要有3部分:数据成员、构造方法、方法成员。

首先看下边的代码,是一个简单的Java类:

package com.csst.vo;

public class Customer {

//1.数据成员

private String custname;

private String pwd;

private Integer age;

//2.构造方法

public Customer() {

}

public Customer(String custname, String pwd) {

this.custname = custname;

this.pwd = pwd;

}

public Customer(String custname, String pwd, Integer age) {

super();

this.custname = custname;

this.pwd = pwd;

this.age = age;

}

//3.方法成员

public String getCustname() {

return custname;

}

public void setCustname(String custname) {

this.custname = custname;

}

public String getPwd() {

return pwd;

}

public void setPwd(String pwd) {

this.pwd = pwd;

}

public Integer getAge() {

return age;

}

public void setAge(Integer age) {

this.age = age;

}

}