当前位置: 技术问答>java相关
关于继承的小问题!
来源: 互联网 发布时间:2015-05-16
本文导语: public class MsgSocket extends Socket { public InputStream in; public OutputStream out; public BufferedReader br; public PrintWriter pw; public MsgSocket(String hostName,int PORT) throws UnknownHostException, IOException { try{ ...
public class MsgSocket extends Socket {
public InputStream in;
public OutputStream out;
public BufferedReader br;
public PrintWriter pw;
public MsgSocket(String hostName,int PORT) throws UnknownHostException, IOException
{
try{
super(hostName,PORT);
in = this.getInputStream();
out = this.getOutputStream();
br = new BufferedReader(new InputStreamReader(in));
pw = new PrintWriter(out,true);
}catch(Exception e){
System.out.println(e);
}
}
public void Start()
{
}
public MsgSocket(){
super();
}
}
以上的程序为什么在编译时会如下出错呢?
Error#:361:method required,but value found as line 28,columan 9
即super(hostName,PORT);
谢谢!
public InputStream in;
public OutputStream out;
public BufferedReader br;
public PrintWriter pw;
public MsgSocket(String hostName,int PORT) throws UnknownHostException, IOException
{
try{
super(hostName,PORT);
in = this.getInputStream();
out = this.getOutputStream();
br = new BufferedReader(new InputStreamReader(in));
pw = new PrintWriter(out,true);
}catch(Exception e){
System.out.println(e);
}
}
public void Start()
{
}
public MsgSocket(){
super();
}
}
以上的程序为什么在编译时会如下出错呢?
Error#:361:method required,but value found as line 28,columan 9
即super(hostName,PORT);
谢谢!
|
super语句必须在所有构造函数的第一句,把super(hostName,PORT);放在第一行即可
|
public MsgSocket(String hostName,int PORT) throws UnknownHostException, IOException
看看这个申明,没有返回类型
看看这个申明,没有返回类型
|
好象就这些了