//CADSystem.java
//Ensuring proper cleanup
import java.util.*;class Shape{
Shape(int i){
// Shape(int ){
System.out.println("Shape constructor");
}
void cleanup(){
System.out.println("Shape cleanup");
}
}class Circle extends Shape{
Circle(int i){
super(i);
System.out.println("Drawing a Circle");
}
void cleanup(){
// viod cleanup(){
System.out.println("Erasing a Circle");
super.cleanup();
}
}class Triangle extends Shape{
Triangle(int i){
super(i);
System.out.println("Drawing aTriangle");
}
void cleanup(){
System.out.println("Erasing a Triangle");
super.cleanup();
}
}class Line extends Shape{
//class Line extends shape{
private int start, end;
Line(int start,int end){
super(start);
this.start=start;
this.end=end;
System.out.println("Drawing a Line:"+
start+","+end);
super.cleanup();
}
}public class CADSystem extends Shape {
private Circle c;
private Triangle t;
private Line[] lines = new Line[10];
CADSystem(int i){
super(i + 1);
for(int j=0;j<10;j++)
lines[j]=new Line(j, j*j); c=new Circle(1);
// c=new Cirle(1);
t=new Triangle(1);
System.out.println("Combined constructor");
}
void cleanup(){
System.out.println("CADSystem.cleanup");
t.cleanup();
c.cleanup();
for(int i=0;i<lines.length;i++)
lines[i].cleanup();
super.cleanup();
}
public static void main (String[] args){
CADSystem x=new CADSystem(47);
try{
//Code and exception handling...
}finally{
x.cleanup();
}
}
}现在可以了。
错误我已经通过注释注明了,都是搞错字的错误,以后仔细点。
//Ensuring proper cleanup
import java.util.*;class Shape{
Shape(int i){
// Shape(int ){
System.out.println("Shape constructor");
}
void cleanup(){
System.out.println("Shape cleanup");
}
}class Circle extends Shape{
Circle(int i){
super(i);
System.out.println("Drawing a Circle");
}
void cleanup(){
// viod cleanup(){
System.out.println("Erasing a Circle");
super.cleanup();
}
}class Triangle extends Shape{
Triangle(int i){
super(i);
System.out.println("Drawing aTriangle");
}
void cleanup(){
System.out.println("Erasing a Triangle");
super.cleanup();
}
}class Line extends Shape{
//class Line extends shape{
private int start, end;
Line(int start,int end){
super(start);
this.start=start;
this.end=end;
System.out.println("Drawing a Line:"+
start+","+end);
super.cleanup();
}
}public class CADSystem extends Shape {
private Circle c;
private Triangle t;
private Line[] lines = new Line[10];
CADSystem(int i){
super(i + 1);
for(int j=0;j<10;j++)
lines[j]=new Line(j, j*j); c=new Circle(1);
// c=new Cirle(1);
t=new Triangle(1);
System.out.println("Combined constructor");
}
void cleanup(){
System.out.println("CADSystem.cleanup");
t.cleanup();
c.cleanup();
for(int i=0;i<lines.length;i++)
lines[i].cleanup();
super.cleanup();
}
public static void main (String[] args){
CADSystem x=new CADSystem(47);
try{
//Code and exception handling...
}finally{
x.cleanup();
}
}
}现在可以了。
错误我已经通过注释注明了,都是搞错字的错误,以后仔细点。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货