• 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

Class type variables

 
Greenhorn
Posts: 2
Tomcat Server Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi friends,
I very much like your Head First series and wanna learn more with it.
But i do not get why a statement is written like the below , which is actually trying to declare a variable of another class type. Say, if there is a class Payroll, then,

public Payroll salary;

Now i understand, Payroll is a class that has getters and setters of few parameters. Now while above statement is used in a different class,
what is achieved by declaring a variable like this ? ; How will the variable 'salary' be used to assign a value in further statements ?
whats the difference in usage between the above statement and declaring a statement like: "public long salary;"

If my question looks stupid or if you understand the basic problem in my understanding, which article should i refer to get a basic understanding of this concept.
Thanks in advance for spending your valuable time explaining me on my doubt.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is not a statement, but a declaration of a public field. Make all your fields, except for global constants, private. You assign to it the same way you assign to anything elseWhat you achieve is not having to write the entire Foo class again. I think you need to go back and read what it says in Head First Java about objects and object‑orientation. There is quite a lot.
 
Haresh Narayanan
Greenhorn
Posts: 2
Tomcat Server Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks Campbell.
I shall refer Head first Java on this . If my doubt still remains, I would get back to you guys on this again ;)
Thanks again.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
reply
    Bookmark Topic Watch Topic
  • New Topic