类(class)是Java 语言的最小编程单位,也是设计和实现Java 程序的基础,本部分将深入介绍类的相关知识。
类的概念
类是一组事物共有特征和功能的描述。类是对于一组事物的总体描述,是按照面向对象技术进行设计时最小的单位,也是组成项目的最基本的模块。类的概念是抽象的,类似于建筑设计中的图纸,是对于现实需要代表的具体内容的抽象。类只包含框架结构,而不包含具体的数据。所以类代表的是总体,而不代表某个特定的个体。
我的总结:类是抽象的,对象是具体的,实实在在的!
类的定义:
[修饰符] class 类名{
1~n个构造方法;
0~n个字段;
0~n个方法
}
定义类,其实就是定义类里面的对象
对象包含:
状态;(属性)
功能、行为;(方法)
通过类来描述对象;
状态--------成员变量;
功能、行为——方法;
Eg:
class Person{
//属性
private String name;
private int age;
private int sal;
//方法
public void show(){
System.out.println("个人情况:"+name+age+sal);
}
}