请教extends的问题 |
尚未結案
|
fangwy
中階會員 發表:99 回覆:139 積分:62 註冊:2003-09-10 發送簡訊給我 |
我的代码如下:
import java.io.*;
import java.net.*;
import java.util.*; public class MulticastServer{
public static void main(String args[]) throws java.io.IOException
{
new MulticastServerThread().start();
//启动一个服务器线程
}
} class MulticastServerThread extends QuoteServerThread
//从QuoteServerThread继承得到新的服务器线程类MulticastServerThread
{
private long FIVE_SECONDS=5000; //定义常量,5秒钟
public MulticastServerThread(String name) throws IOException
{
super("MulticastServerThread");
//调用父类,也就是QuoteServerThread的构造函数
}
.
.
.
} //服务器线程
class QuoteServerThread extends Thread
{
protected DatagramSocket socket=null;
//记录和本对象相关联的DatagramSocket对象
protected BufferedReader in=null;
//用来读文件的一个Reader
protected boolean moreQuotes=true;
//标志变量,是否继续操作 public QuoteServerThread() throws IOException {
this("QuoteServerThread");
}
public QuoteServerThread(String name) throws IOException {
super(name); //调用父类的构造函数
socket=new DatagramSocket(4445);
//在端口4445创建数据报套接字
try{
in= new BufferedReader(new FileReader("one-liners.TXT"));
//打开一个文件,构造相应的BufferReader对象
}catch(FileNotFoundException e) { //异常处理
System.err.println("Could not open quote file. Serving time instead.");
//打印出错信息
}catch(IOException e){}
}
.
.
.
} 可是编译时提示:
MulticastServer.java:9: cannot resolve symbol
symbol : constructor MulticastServerThread ()
location: class MulticastServerThread
new MulticastServerThread().start();
^
1 error 我将下面一段注释掉:
/* public MulticastServerThread(String name) throws IOException
{
super("MulticastServerThread");
//调用父类,也就是QuoteServerThread的构造函数
}*/
编译时又提示
MulticastServer.java:16: unreported exception java.io.IOException in default constructor
class MulticastServerThread extends QuoteServerThread
^
1 error 我是一个JAVA的初学者,请各位大大指导,谢谢!
|
rogan321
高階會員 發表:21 回覆:307 積分:200 註冊:2003-05-15 發送簡訊給我 |
Hi~fangwy你下面紅色地方的變數是什麼型態,有宣告嗎~
引言: 我的代码如下: import java.io.*; import java.net.*; import java.util.*; public class MulticastServer{ public static void main(String args[]) throws java.io.IOException { new MulticastServerThread().start(); //启动一个服务器线程 } } class MulticastServerThread extends QuoteServerThread //从QuoteServerThread继承得到新的服务器线程类MulticastServerThread { private long FIVE_SECONDS=5000; //定义常量,5秒钟 public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 } . . . } //服务器线程 class QuoteServerThread extends Thread { protected DatagramSocket socket=null; //记录和本对象相关联的DatagramSocket对象 protected BufferedReader in=null; //用来读文件的一个Reader protected boolean moreQuotes=true; //标志变量,是否继续操作 public QuoteServerThread() throws IOException { this("QuoteServerThread"); } public QuoteServerThread(String name) throws IOException { super(name); //调用父类的构造函数 socket=new DatagramSocket(4445); //在端口4445创建数据报套接字 try{ in= new BufferedReader(new FileReader("one-liners.TXT")); //打开一个文件,构造相应的BufferReader对象 }catch(FileNotFoundException e) { //异常处理 System.err.println("Could not open quote file. Serving time instead."); //打印出错信息 }catch(IOException e){} } . . . } 可是编译时提示: MulticastServer.java:9: cannot resolve symbol symbol : constructor MulticastServerThread () location: class MulticastServerThread new MulticastServerThread().start(); ^ 1 error 我将下面一段注释掉: /* public MulticastServerThread(String name) throws IOException { super("MulticastServerThread"); //调用父类,也就是QuoteServerThread的构造函数 }*/ 编译时又提示 MulticastServer.java:16: unreported exception java.io.IOException in default constructor class MulticastServerThread extends QuoteServerThread ^ 1 error 我是一个JAVA的初学者,请各位大大指导,谢谢! |
fangwy
中階會員 發表:99 回覆:139 積分:62 註冊:2003-09-10 發送簡訊給我 |
|
rogan321
高階會員 發表:21 回覆:307 積分:200 註冊:2003-05-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |