• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic