• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic