• 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Inner class Constructor

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is a question from javaworld
1. Given the following class definition:
<pre>
class A
{
protected int i;
A(int i)
{
this.i = i;
}
}
Which of the following would be a valid inner class for this class? Select all valid answers.
A.class B {}
B.class B extends A {}
C.class B
{
B()
{
System.out.println("i = " + i);
}
}
D.class B
{
class A {}
}
E.class A {}
</pre>
Ans: a) and c)
IMO there is no default (no arg) constructor in class A
then how come ans c) is correct? constructor in class B which is also no arg constructor will try to call default constructor in A? then why ans b) is wrong??
Maha , Jim i need your help here,
thank you

------------------

[This message has been edited by maha anna (edited April 07, 2000).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shiva,
Please use the formating tags [ code ] [ /code] around your sample code. Or you can use the html tags < pre> < /pre> all tags without the space inside them.
The ans. given are correct and your thinking is also correct. But you didn't apply it properly I think. Please read the ans carefully. ans b) is wrong because this is the one which extends class A and needs the A() in A class. Since it is not there in A, this ans is wrong.
Ans c) is correct because This is just an ordinaryinner class which does not extend A. It is perfectly fine.
Please refer to this. I also request all to use the 'search' facility liberally at the top-right of every page.
regds
maha anna

[This message has been edited by maha anna (edited April 07, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you maha,
i didnt know about those formatting tags, will use from now onwards and i think now i am clear on constructors
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic