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

Question: inner class

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I chose a,b,c.
But the answer says a,c.
Is "b" incorrect?

From my part, B is inner as well as extending class A.


Regards,
cmbhatt
[ April 12, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put in the inner class:

class B extends A { }

into Class A, it would not compile.

Compiler will complain about A not having the default constructor A(). The compiler will define a default constructor in class B that will attempt to call no-arg constructor in class A

i.e B() { super() };

But Class A has no no-arg constructor because there is already an explicit constructor that takes an int primitive A(int i). No default constructor will be inserted in to A by the compiler. So A will need an explicit constructor A(){ } in order for the class to compile with the inner class B extends A.

I think that's the right explanation ...
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O I SEE!

Great Young, in the first ball you made the ball out of boundary.

BTW, welcome to JavaRanch

Thanks,
cmbhatt
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

Steven is right of course.
But I'd like to add, that this is an example of how you can be fooled in the exam.

Because in a first look, answer c) looks all right.

Only the fact that it cannot compile doesn't have anything to do with inner classes... As it would not compile in a top level class either.

That's how the exam makers want to catch you!


Bu.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic