• 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

Compilation error on different line number

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


In the above code, you get a compilation error on line 5 saying comma is expected instead of semicolon.
However, I was expecting the error on line 6 as I was modifying a final variable from a parent class.  While I can see, if I change the code to :


There is no compilation error. Makes sense!
But the line number of the compilation error is confusing to me in the sense such kind of questions are asked in OCAJP where we are expected to know the line number where the compilation error comes.

Do you know any other example similar to this one? Thanks!
 
Marshal
Posts: 79471
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That tells you how difficult it is to write good compiler error messages. Yes, you would have expected the compiler to complain about trying to reassign a final field, but that is a statement, and statements are only permitted in methods, constructors, initialiser, etc. That is code lying free in the class, where only declarations are permitted. If it is a declaration, it hasn't got a type, so the likeliest error is that it is part of the previous declaration. It will compile asYou are declaring the same field twice in two classes, which is dubious and error‑prone design, and you are declaring two fields in the same line, which is poor style. In fact both those offences against good programming should be banned everywhere . . . except in cert. exams
 
Neha Agnihotri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for the explanation. It's much clear now.

PS: I am really amazed how quickly I get answers/explanation on this forum. A big Thank You to all of you!
 
Campbell Ritchie
Marshal
Posts: 79471
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neha Agnihotri wrote:. . . thanks . . . Thank You . . .

That's a pleasure We try to provide a good service.
reply
    Bookmark Topic Watch Topic
  • New Topic