想抽象个物体,但不懂如何开始,希望高手能举个例子详解..重要的是思想
解决方案 »
- 谁能告诉我它们到底有什么区别
- 关于事件监听与回调的实现方法。
- 接口方面问题,不知道为什么编译错误。希望各位帮忙看一下!
- "AWT-EventQueue-0" java.lang.NullPointerException 问题
- 大家帮帮看看这段代码的是不是有逻辑问题
- eclipse 总是提示溢出怎么办?
- 怎样用java构造post数据包发送到服务端
- 再次问一下FileWriter以及BufferedWriter这样的文件读写类和操作系统有关吗??急!
- super急!!!!!!!!!
- SOCKET的问题:高手看下,为什么死琐啊??????
- 关于通信录程序的几个小问题,请高手解决一下
- 单击jButton按钮无法显示jTable内容
String name = "奇瑞QQ";
String color = "红";
void run(){
System.out.println("每小时80公里");
}
}这个意思?
我抽象的是个苹果:import java.io.*;
public class apple{
String shape;
String colour;
后面我就不知道怎么写下去了,还不知道对不对 所以想请高手帮忙指导下,最好举个例子并分析下,指导下思想,让我知道怎么抽象个物体.
public class Apple {
String shape;
String colour;
Apple()
{
shape="";
colour="";
}
public String eat()
{
//eating
return "好吃!";
}
public String getShape()
{
return shape;
}
public String getColour()
{
return colour;
}
}
public class Apple {
private String shape;
private String color;
// 无参数传递
public Apple() {
shape = "";
color = "";
}
// 传递形状和颜色
public Apple(String shape, String color) {
this.shape = shape;
this.color = color;
}
// 传递形状
public Apple(String shape) {
this.shape = shape;
this.color = "";
}
// 传递颜色
public Apple(String color) {
this.color = color;
this.shape = "";
}
// 当然也可以通过SET方法传递
public void setShape(String shape) { this.shape = shape; }
public void setColor(String color) { this.color = color; }
}应该是这样吧