java开发实战经典(第二版)P217 6-2

论坛 期权论坛 脚本     
匿名技术用户   2020-12-28 00:19   409   0

6.2 考虑一个表示图形的类,写出类中的属性及方法。

package book;

class Graph {
 private float length;
 private float width;
 private String backcolor;

 public float getLength() {
  return length;
 }

 public void setLength(float length) {
  this.length = length;
 }

 public float getWidth() {
  return width;
 }

 public void setWidth(float width) {
  this.width = width;
 }

 public String getBackcolor() {
  return backcolor;
 }

 public void setBackcolor(String backcolor) {
  this.backcolor = backcolor;
 }

 public void size() {
  System.out.println("设置图片的尺寸");
 }

 public void color() {
  System.out.println("设置图片的背景颜色");
 }
}

public class JiOu {
 public static void main(String[] args) {
  Graph graph = new Graph();
  graph.size();
  graph.color();
 }
}

运行结果:

设置图片的尺寸
设置图片的背景颜色

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP