• Post Reply Bookmark Topic Watch Topic
  • New Topic

Initializing an object at class level  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we initialize an object at class level ?
How can we use the methods of this class if its initialized at class level , because reference to this class is also at class level and not in main ?

Thanks
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Eclipse IDE Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use static methods and variables
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rupesh Mhatre wrote:use static methods and variables
Disagree. Don't make them static.

You can have objects (reference types) as fields. You initialise them (probably in your constructor) and then your methods can call methods on those objects.
You should be getting right out of the main method. Use the main method to start your application, then get into other methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!