关与抽象类的问题
package Java;
import java.util.*;
public class SeqList
{
final int defaultSize = 10;
int maxSize;
int size;
Object[]ArrayList;
public SeqList()
{
initiate(defaultSize);
}
public SeqList(int size)
{
initiate(size);
}
private void initiate(int size)//插入字符
{
maxSize = size;
size = 0;
ArrayList = new Object[size];//初始化
}
public void insert(int i,Object obj)throws Exception
{
if (size == maxSize)
{
throw new Exception( "顺序满了 无法插入字符了 ");
}
for (int j = size;j> i;j++ )
{
ArrayList[j] = ArrayList[j-1];
ArrayList[i] = obj;
size++;
}
}
public Object delete(int i)throws Exception
{
if (size == 0)
{
throw new Exception( "顺序表已经空了 没办法删了 ");
}
if (i <0||i> size-1)
{
throw new Exception( "参数错误!!! ");
}
Object it = ArrayList[i];
for (int j = i;j <size-1 ;j++ )
ArrayList[j] = ArrayList[j+1];
size--;
return it;
}
public Object getData(int i)throws Exception //获取指定的数组元素
{
if (i <0||i> =size)
{
throw new Exception( "参数错误!!! ");
}
return ArrayList;
}
public int size()//元素个数
{
return size;
}
public boolean isEmpty()//测试是否为空
{
return size == 0;//fan hui false
}
public int MoreDataDlete(SeqList L,Object x)throws Exception
{
int i,j;
int tag = 0;
for ( i = 0;i <L.size ;i++ )
{
if (x.equals(L.getData(i)))
{
L.delete(i);
i--;
tag=1;
}
}
return tag;
}
}
package Java;
import java.util.*;
public class SeqListTest
{
public static void main(String[] args)
{
SeqList s = new SeqList(100);
int n = 10;
try
{
for (int i = 0;i <n ;i++ )
{
s.insert(i,new Integer(i+1));
}
s.delete(4);
for (int i = 0;i <s.size ;i++ )
{
System.out.println(s.getData(i)+ " ");
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
我在运行SeqListTest的时候出现SeqListTest.java:7: Java.SeqList 是抽象的;无法对其进行实例化
SeqList s = new SeqList(100);
1 错误
我实在想不出来哪里除了问题
这是书上的例子 应该不会出现这样的问题的
请高手指教..
感激不尽..
------解决方案--------------------没错呀..你好好再看看吧.........不过好像在最后少了一个 } 括号