• 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

K&B Self Test qes- Inner classes

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In K&B chapter 8 ,self test question 4 pg 666,
can anybody please help me exaplaining how answers are : B and C.
FOr correct anonymous inner classes
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which part of the explanation (on page 667) are you questioning?
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc,
Prgram is about Inner classes on pg 660/666
and we have to tell which one out of given options creates an anonymous class from within class Bar.
I coldnt understand why answer is B and C.
class Boo{
Boo(){}
Boo(String s){} }

class Bar extends Boo{
Bar(){}
Bar(String s){ super(s);}
void zoo(){.........insert code here.}}

Options:
a. Boo f=new Boo(24);
b. Boo f=new Bar(){}; -- correct anser
c. Boo f =new Boo(){String s;} --correct anser
d. Boo f=new Boo(String s){}; //
e. Boo f=new Boo.Bar(String s){};

HOw b and c are creating anonymous inner (sub) classes here ,
how d is not.we have 1-arg constructor also
,
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


would have been also the right answer if it were

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic