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 Enthuware question doubt 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 "Enthuware question doubt" Watch "Enthuware question doubt" New topic
Author

Enthuware question doubt

Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

I got the question from here(Qno: 14)..

The answers are given as c and d ...
I believe only d is correct and how can we can know about the nature of anonymous class??

Thanks
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Hareendra Reddy wrote:I got the question from here(Qno: 14)..

The answers are given as c and d ...
I believe only d is correct and how can we can know about the nature of anonymous class??

Thanks

Dear friend..... c AND d are correct! A class created INSIDE a method (including static methods) is called METHOD-LOCAL-INNER-CLASS.
The same rules apply to LOCAL VARIABLE DECLARATIONS.
The ONLY modifiers you can use are either abstract OR final. NEVER both at the same time!!.
So c is correct! as well as d.

Try this:


Remember that I am studying java just like you AND others, DO NOT rely on me 100%, I am NOT above mistakes. Thank you for your understanding.

Hey! After reading CAREFULLY the options I agree with you that option c is wrong!.
Here is my understanding:
1. class created inside the main method "IS" final.
2. class created inside the main method "CAN BE" final. // this sounds better.


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

Thank you Ikpefua Jacob-Obinyan ...

Yeah you are saying right, anonymous inner classes are similar to method lcoal inner classes...
But we didn't mark the class final (any way we can't) , then how can we say that it is final ??
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Hareendra Reddy wrote:Thank you Ikpefua Jacob-Obinyan ...

Yeah you are saying right, anonymous inner classes are similar to method lcoal inner classes...
But we didn't mark the class final (any way we can't) , then how can we say that it is final ??


It is NOT final and at the moment I have NOT seen such a syntax, I seriously doubt if it exists.

Let us analyse line 15 of your code READ CAREFULLY:



Observation:
Did you take note of the semi-colon that ends the curly braces in line 11 ??
That is how to know an anonymous inner class.
The semi colon ought to have ended the instance declaration in line 4!! but it did not!!
That is how you identify anonymous inner classes.
The SOLE purpose of anonymous inner class is to override methods.
I am sorry I dont have more details, you will have to investigate that yourself. Thanks.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3312
    
    7
Hello,
The given answer is correct.
From Java Language Specification:

15.9.5 Anonymous Class Declarations
An anonymous class declaration is automatically derived from a class instance creation expression by the compiler.
An anonymous class is never abstract (§8.1.1.1). An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.2). An anonymous class is always implicitly final (§8.1.1.2).


HTH,
Paul.

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

Joined: Aug 31, 2010
Posts: 394

Paul Anilprem wrote:Hello,
The given answer is correct.
From Java Language Specification:

15.9.5 Anonymous Class Declarations
An anonymous class declaration is automatically derived from a class instance creation expression by the compiler.
An anonymous class is never abstract (§8.1.1.1). An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.2). An anonymous class is always implicitly final (§8.1.1.2).


HTH,
Paul.

Thanks Paul...I was NOT sure about the issue of final in an anonimous classes and this information is FUNDAMENTAL to learners like us.
Once again thanks for your intervention.
Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

Thank you Paul Aniprem...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enthuware question doubt