File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQplus (Trial Version) question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQplus (Trial Version) question" Watch "JQplus (Trial Version) question" New topic
Author

JQplus (Trial Version) question

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
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
jeena jose
Ranch Hand

Joined: May 06, 2001
Posts: 69
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
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
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).]
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3293
    
    7
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).]


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
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
Ranch Hand

Joined: Sep 23, 2000
Posts: 3293
    
    7
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

Joined: Mar 16, 2001
Posts: 216
Hi Paul,
Are you trying to tell that choice (4) can also be true.
Please clear my doubt.
Ravindra Mohan..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQplus (Trial Version) question