• Post Reply Bookmark Topic Watch Topic
  • New Topic

(Programming Taglib)Why I must place this object in constructor?

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I delete the "public BookManager(){ }".The code report error:"Can't solve the charactor tbook"
It means I must place the object "Testfor tbook" in the constructor ?(Testfor is a class that I wrote.
//////////////////////////////////My code is://////////////////////////////////
public class BookManager{
private static BookManager instance=new BookManager();
Hashtable hbook=new Hashtable();
public BookManager(){ //<--------------If delete the sentence the compiler report error///////////////////////////////////////////
Testfor tbook;
tbook=new Testfor("345463463","Beginning Java Programming");
hbook.put(tbook.getIsbn(),tbook);
tbook=new Testfor("10231334","Beginning C# Builder");
hbook.put(tbook.getIsbn(),tbook);
tbook=new Testfor("0120130","Study C++ in 21 days");
hbook.put(tbook.getIsbn(),tbook);
tbook=new Testfor("4643564","Mastering EJB");
hbook.put(tbook.getIsbn(),tbook);
}
public static BookManager getInstance(){
return instance;
}
public Testfor getTestfor(String isbn){
return (Testfor)hbook.get(isbn);
}
public Testfor[] getBookAsArray(){
return (Testfor[])hbook.values().toArray(new Testfor[0]);
}
public Collection getBookAsCollection(){
return hbook.values();
}
}
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I means whether tbook must be declared inside the constructor.I think the answer is "no" also.But if I place the tbook outside the constructor and the compiler report error:"Can't solve the charactor tbook"?Why?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!