Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

anonymous inner class

 
gangqiang zhang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,everybody

Given the following,



Which two create an anonymous inner class from within the class Bang ?

  • Bang b = new Bing("Foo"){};
  • Bing b = new Bing(343){};
  • Bing b = new Bing(){"Foo";};
  • Bing b = new Bang(){};
  • Bing b = new Bing.Bang("Foo"){};



  • The reference answer is C & D.Why the answer C is correct answer? Could anybody give me a explanation.
     
    Seb Mathe
    Ranch Hand
    Posts: 225
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Imagine that the statement Super(bangs); is replaced with super(bangs) (code won't compile otherwise), C is incorrect because the statement "Foo"; is invalid.
     
    gangqiang zhang
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks, seb

    The question is on the CD of K&B's book.
     
    Kevin Lam
    Ranch Hand
    Posts: 68
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    what makes the answer>annonymous class ? I thought to make it annonymous you haveto extends or implements there and then the answer looks like a normal innerdass only
     
    gangqiang zhang
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thx,
     
    gangqiang zhang
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Hence,I can get another anonymouse inner class like the preceding code.It is a subclass of Bing class.

    Regards

    zhang
     
    Leoo yu
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    That's lapsus calami .
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic