| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 498 人关注过本帖
标题:请教一个问题,关于数组怎么就执行了一次,
取消只看楼主 加入收藏
jxry8888
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-8-13
收藏
 问题点数:0 回复次数:2 
请教一个问题,关于数组怎么就执行了一次,

import java.util.*;
class Shape{
Shape(int i){
System.out.println("Shape Cons");
}
void dispose(){
System.out.println("shape dispose");
}
}

class Triangle extends Shape{
Triangle( int i){
super(i);
System.out.println("Triangle Cons");
}
void dispose(){
System.out.println("Triangle dispose");
}
}

class Line extends Shape{
private int start,end;
Line( int start, int end ){
super(start);
this.start = start;
this.end = end;
System.out.println("Draw Line" + start + ", " + end);
}
void dispose(){
System.out.println("Erasing Line " + start + " ," + end);
}
}

public class compos_inher extends Shape{
private Triangle t;
private Line[] lines = new Line[4];
public compos_inher( int i){
super( i + 1 );
t = new Triangle(1);
for( int j = 0; j < 4; j++)
lines[i] = new Line(i,i*i); //起码应该循环四次,结果单步跟踪一次就结束 了
System.out.println("Combined Cons");
}
public void dispose(){
System.out.println("CADsystem dispose");
t.dispose();
for( int j = lines.length; j > 0; j--){
lines[j].dispose();
super.dispose();
}//
}
public static void main(String[] args){
compos_inher x = new compos_inher(45);
try{
}finally{
x.dispose();
}
}
}
//编译器就打印了如下
Shape Cons
Shape Cons
Triangle Cons
Shape Cons
Draw Line45, 2025
并跑出异常
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 45
at compos_inher.<init>(compos_inher.java:202)
at compos_inher.main(compos_inher.java:214)
小弟不懂,请各位帮忙解决...谢谢.

搜索更多相关主题的帖子: void private import super start 
2007-02-08 01:41
jxry8888
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-8-13
收藏
得分:0 
怎么没有哪位帮忙呀.?

2007-02-08 03:24
jxry8888
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-8-13
收藏
得分:0 
哦,不好意思了,是我看错了,其实我是想表示j而不是j....

2007-02-08 11:42
快速回复:请教一个问题,关于数组怎么就执行了一次,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017661 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved