类是一种用户自定义的数据类型,定义了对象的属性和方法。 // 定义类class Rectangle { public int width; // 宽度属性 public int height; // 高度属性 public int Area() { return width * height; // 计算面积 }}// 使用类Rectangle rect = new Rectangle();rect.width = 5;rect.height = 3;int area = rect.Area(); // 运行结果:面积为15 类中的属性和方法可设置访问修饰符,控制访问权限。