• Post Reply Bookmark Topic Watch Topic
  • New Topic

A really silly problem .But cant figure out how ?  RSS feed

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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 :


 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... but you ought to have the field labelled private and set up its value via a constructor.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!