This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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

Anonymous Class

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



here for the anonymous class face it is not ending with a semicolon
but even then it compiles fine how and why?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...erm. Not sure I get the problem. Why do you believe a semi-colon is needed?
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Craig,

because according to K&B syntax for a anonymous class, anonymous class should end with a semicolon. Where they have stressed a lot of time that semicolon must be inserted.

do you think i have wrongly intrepeted the statments.
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srinivas sridaragaddi:

because according to K&B syntax for a anonymous class, anonymous class should end with a semicolon.


This is true but when you create anonymous inner class as follows:
 
Craig Bayley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Possibly...But I'm not willing to deny someone else's interpretation without seeing the material first hand.

All I can tell you is that I have used this code without semi-colons, and my understanding is they are not needed. I may have to do some more "deep thought" and some back later.
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

All I can tell you is that I have used this code without semi-colons, and my understanding is they are not needed.



craig why do you think that semicolon is not needed. whats your thought behind that. can you please explain?
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too think semi-colon is needed
in the anonymous inner class


Well i am not sure,if i am right or not
but may be in this case as we are passing
the instance of class as parameter to the method

seth(new face(){});
so it(semi-colon) is not required..!!!
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anonymous classes do not NEED to end in a semicolon. The statement which defines such a class needs too and that is sufficuent.

Your example is explained on page 19 of the chapter with the class MyWonderfulClass, there is only one semicolon on line 8 and not two. Bascically, the the semicolon on line 1 in your example ends both the inner class def along with the statement.
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need the semicolon to end the statement that you started, when you say:

This declaration of the reference variable is its self a statement, hence needs semicolon.
 
Nothing? Or something? 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