Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic