• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Enthuware question doubt

 
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Enthuware Software Support
Posts: 4646
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul Aniprem...
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic