• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

K&B Self Test qes- Inner classes

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator


would have been also the right answer if it were

 
mooooooo ..... tiny ad ....
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic