• 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

A really silly problem .But cant figure out how ?

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks ,
Im trying to write two classes in the same package as follows.
Class1

Class 2- Here i try to create an object of Supplier class and access the supName field, but the compiler throws an error.

Could anyone shed some light on why this is happening?
Thanks.
 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post details of your error messages for our information and convenience.
Ok, s1.supName should be placed inside a method/constructor body. (See that in your original program, doing s1.supName = "vic hOOD"; will ALSO give a compiler error.)

The code :


BUT ! This code will still not work ! Because s1.supName; is NOT a statement, as shown by the compiler.
A statement is a variable declaration , variable assignment or a method call.

Source : http://www.docstoc.com/docs/9849500/What-is-a-Java-Statement

So change the code as follows and it compiles :


 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... but you ought to have the field labelled private and set up its value via a constructor.
 
reply
    Bookmark Topic Watch Topic
  • New Topic