本帖最后由 李大伟 于 2012-9-24 10:51 编辑
各位同学,毕老师课程day19 前边讲过一个MyBufferedReader ,
然后后边讲 MyLineNumberReaderDemo时,class myLineNumberReader extends MyBufferedReader 继承了 MyBufferedReader ,这个继承的话是怎么继承的,是因为我之前在day19这个文件夹里有MyBufferedReader.java 和 MyBufferedReader.class 吗,假如没有呢
求解释!!!
import java.io.*;
class myLineNumberReader extends MyBufferedReader
{
private int lineNumber;
MyLineNumberReader(Reader r)
{
super(r);
}
public String myReadLine() throws IOException
{
lineNumber++;
return super.myReadLine();
}
public void setLineNumber(int lineNumber)
{
this.lineNumber=lineNumber;
}
public int getLineNumber()
{
return lineNumber;
}
}
class MyLineNumberReaderDemo
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args) throws IOException
{
FileReader fr=new FileReader("copyTextByBuf.java");
MyLineNumberReader mylnr=new MyLineNumberReader(fr);
String line=null;
mylnr.setLineNumber(100);
while ((line=mylnr.myReadLine())!=null)
{
sop(mylnr.getLineNumber()+":"+line);
}
mylnr.myClose();
}
}
|
|