• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class type variables  RSS feed

 
Haresh Narayanan
Greenhorn
Posts: 2
Chrome Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • 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.

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • 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
Chrome Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • 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: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!