当前位置: 技术问答>java相关
使用重载的构造函数就出错!!!
来源: 互联网 发布时间:2015-05-05
本文导语: book.java 如下: package library; public class Book { private String title; public Book(){} public Book(String t) { this.title=t; } public String getTitle() { return title; } public void setTitle(String ti...
book.java 如下:
package library;
public class Book
{
private String title;
public Book(){}
public Book(String t)
{
this.title=t;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title=title;
}
}
bookpage.jsp 如下:
A Simple Class
|
:使用重载的构造函数就出错!!!
没有错误啊,例如下面就是好用的:
class Book
{
private String title;
public Book(){}
public Book(String t)
{
this.title=t;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title=title;
}
}
public class testC
{
public static void main(String args[])
{
Book b = new Book();
Book b1 = new Book("hello");
}
}
没有错误啊,例如下面就是好用的:
class Book
{
private String title;
public Book(){}
public Book(String t)
{
this.title=t;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title=title;
}
}
public class testC
{
public static void main(String args[])
{
Book b = new Book();
Book b1 = new Book("hello");
}
}
|
报什么错?
|
将错误贴出来,应该是对的!!!