• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comments - Dan's exam question

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is a question from Dan's Funda exam 4:
1. class Red {
2. // Comment1
3. // // Comment2
4. /* Comment3 */
5. /* Comment4
6. */
7. /** Comment5 */
8. // /* Comment6 */
9. /* // Comment7 */
10. /* /* Comment8 */
11. /** /* // Comment9 // /* */
12. /* Comment10 */*/
13. /* Comment11 /* Comment12 */ */
14. }

What is the result of attempting to compile the program?
a. Compiler error at line 1.
b. Compiler error at line 2.
c. Compiler error at line 3.
d. Compiler error at line 4.
e. Compiler error at line 5.
f. Compiler error at line 6.
g. Compiler error at line 7.
h. Compiler error at line 8.
i. Compiler error at line 9.
j. Compiler error at line 10.
k. Compiler error at line 11.
l. Compiler error at line 12.
m. Compiler error at line 13.
n. None of the Above
Dan's answer is l and m i.e, error at lines 12 and 13, however, I get an error at only line 12.
Also is /** the start of a comment as seen on lines 7 and 11?
I'm confused - I always thought you could nest comments and anything in between /* ... */ was ignored.
Thanks
Sharda
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see The Java Language Specification, Section 3.7, Comments.
Comments do not nest. The end of the nested comment is interpreted as the end of both the nested comment and the end of the enclosing comment. The end of the enclosing comment will then generate a compiler error.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sharda Vajjhala:
Also is /** the start of a comment as seen on lines 7 and 11?
Thanks
Sharda


Yes, /** is the start of a javadoc comment.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic