• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JQplus (Trial Version) question

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the below regarding inner classes is true ?
( any three )
1. A non-static inner class may have static members.
2. Anonymous inner classes cannot have any extends or implements clause.
3. Anonymous inner classes can only be created for interfaces
4. Anonymous classes can never have initialized parameters.
5. Anonymous inner classes cannot be static
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the below regarding inner classes is true ?
( any three )
1. A non-static inner class may have static members.//flase
2. Anonymous inner classes cannot have any extends or implements clause.//true
3. Anonymous inner classes can only be created for interfaces//false
4. Anonymous classes can never have initialized parameters.//false
5. Anonymous inner classes cannot be static //true
2,5 are true
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anjella,
The answers are (2),(4),(5) ?? (see the explanation)


Which of the below regarding inner classes is true ?
( any three )
1. A non-static inner class may have static members. // false, a non-static inner CANNOT have static members
2. Anonymous inner classes cannot have any extends or implements clause. // true, they simply impliment the interface without any
// keyword extends or impliments as they dont have a name.
3. Anonymous inner classes can only be created for interfaces // false , they can be created for other classes as well.
4. Anonymous classes can never have initialized parameters. // true as they dont have name, so no constructor , and no parametes as well
5. Anonymous inner classes cannot be static // NOT CLEAR
// if question is that an anonymous cannot be declared as static then the answer is true BUT we can definitely
have a static anonymous class within a static method so in other case answer is false.


Hope this clears your doubt.
Ravindra Mohan.

[This message has been edited by Ravindra Mohan (edited May 11, 2001).]
 
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct answers are 1, 2 and 5 as given in the s/w.
. You can have static field in a non-static inner class. But you have to make it constant. Obviously, a final static field is static.
ex:
class A
{
class B
{
final static int i = 10; //this is valid.
}
}

. Anonymous class can never be static. Even if defined in a static context. The very syntax conveys the answer. You always do: new ActionListener(){ ... }
HTH,
Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Your guide to SCJD exam!
www.enthuware.com/jdevplus
Try out the world's only WebCompiler!
www.jdiscuss.com
[This message has been edited by Paul Anil (edited May 11, 2001).]
[This message has been edited by Paul Anil (edited May 11, 2001).]
 
Ravindra Mohan
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for the explanation on choice(1) . I missed on that. Could you please explain why the choice(4) cant be
true. May be I have not understood the question??
Ravindra Mohan
 
Paul Anilprem
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can pass parameters to an anonymous class but the parameters must match any of the constructors of the super class.
ex. you can have somthing like:
new SomeClass( 10, 20 ) { }
here, SomeClass must have a constructor that takes 2 ints.
 
Ravindra Mohan
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Are you trying to tell that choice (4) can also be true.
Please clear my doubt.
Ravindra Mohan..
 
reply
    Bookmark Topic Watch Topic
  • New Topic