//AbstractDemo.java
//class AbstractDemopublic class AbstractDemo { //包含抽象方法的 抽象类
abstract class Shape {
int xPosition, yPosition; void setCenterPoint(int xPos, int yPos) {
xPosition = xPos;
yPosition = yPos;
} abstract void draw();
}
//正方形类继承Shape类
class Square extends Shape{
int length;
public Square(int xPos,int yPos,int len){
super.setCenterPoint(xPos,yPos);
length=len;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t Wide length:"+length);
}
}
//圆类继承Shape类
class Circle extends Shape{
int ri;
public Circle(int xPos,int yPos,int r){
super.setCenterPoint(xPos,yPos);
ri=r;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t Wide length:"+ri);
}
}
//三角形类继承Shape类
class Trigon extends Shape{
int bottom;
int highness;
public Trigon(int xPos,int yPos,int bott,int high){
super.setCenterPoint(xPos,yPos);
bottom=bott;
highness=high;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t bottom lenth:"+bottom+"\t Highness "+highness);
}
}
//以Shape类型的对象为参数管理
class ShapeManager{
void manager (Shape shapeObj){
shapeObj.draw();
}
} public static void main(String args[]) { ShapeManager shapeManager = new ShapeManager();
Square square = new Square(10,20,5);
Circle circle=new Circle(20,30,8);
Trigon trigon=new Trigon(30,40,6,4);
System.out.println();
shapeManager.manager(circle);
shapeManager.manager(square);
shapeManager.manager(trigon);
System.out.println();
}}总是在main函数位置出错,我的环境是 eclipse3.1+myeclipse4.0 jdk 5.0
No enclosing instance of type AbstractDemo is accessible. Must qualify the
allocation with an enclosing instance of type AbstractDemo (e.g. x.new A()
where x is an instance of AbstractDemo).
//class AbstractDemopublic class AbstractDemo { //包含抽象方法的 抽象类
abstract class Shape {
int xPosition, yPosition; void setCenterPoint(int xPos, int yPos) {
xPosition = xPos;
yPosition = yPos;
} abstract void draw();
}
//正方形类继承Shape类
class Square extends Shape{
int length;
public Square(int xPos,int yPos,int len){
super.setCenterPoint(xPos,yPos);
length=len;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t Wide length:"+length);
}
}
//圆类继承Shape类
class Circle extends Shape{
int ri;
public Circle(int xPos,int yPos,int r){
super.setCenterPoint(xPos,yPos);
ri=r;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t Wide length:"+ri);
}
}
//三角形类继承Shape类
class Trigon extends Shape{
int bottom;
int highness;
public Trigon(int xPos,int yPos,int bott,int high){
super.setCenterPoint(xPos,yPos);
bottom=bott;
highness=high;
}
void draw() {
// TODO Auto-generated method stub 以(xPos,yPos 为圆心,画出一个边长为length的正方形)
System.out.println("this is a square :\n center :("+xPosition+","+yPosition+")"+"\t bottom lenth:"+bottom+"\t Highness "+highness);
}
}
//以Shape类型的对象为参数管理
class ShapeManager{
void manager (Shape shapeObj){
shapeObj.draw();
}
} public static void main(String args[]) { ShapeManager shapeManager = new ShapeManager();
Square square = new Square(10,20,5);
Circle circle=new Circle(20,30,8);
Trigon trigon=new Trigon(30,40,6,4);
System.out.println();
shapeManager.manager(circle);
shapeManager.manager(square);
shapeManager.manager(trigon);
System.out.println();
}}总是在main函数位置出错,我的环境是 eclipse3.1+myeclipse4.0 jdk 5.0
No enclosing instance of type AbstractDemo is accessible. Must qualify the
allocation with an enclosing instance of type AbstractDemo (e.g. x.new A()
where x is an instance of AbstractDemo).
解决方案 »
- 正则表达式中的\\b是什么?
- java 最接近点对 栈溢出error
- 求:文字比对算法?<--------------高手看过来!
- 我押300分,谁来接分?
- thinking in java中bruce eckel讲到产生sql语句可以使用microsoft query,但是??
- 我是初学小菜,求助!(答者送分)
- 在线给分:使用SmartUpload的问题
- 关于动态菜单项,注意,不是动态菜单(一定给分)
- 如何改变在textarea 中的光标的属性,cursor这个类的属性的代码
- 谁知道?高手请看
- 请教如何在gforge.osdn.net.cn上面上传自己的项目
- 我没分了,麻烦前辈做一下做下作业题,谢谢了
allocation with an enclosing instance of type AbstractDemo (e.g. x.new A()
where x is an instance of AbstractDemo).这是出错信息,英文不好 3ke yu