• Post Reply Bookmark Topic Watch Topic
  • New Topic

class instantiation  RSS feed

 
vijay kumarg
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel sorry if this question irriates any one.
Should classes be instantiated only in main()?
 
Arjun Karthick
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
not needed. you can instanciate your class even out side main that is in other methods, constructors,abstract classes, interface. usually you instanciate a class to get it's methods and variables.

Karthick.j.g
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope.. you can make a class instance at many places one of which includes inside methods(means all methods,static/non-static),and main method is a static method.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should classes be instantiated only in main()?

No - I wonder where you got this idea from. In any non-trivial program, classes are instantiated in almost every method of the program. Can you explain why you think it would be good if classes be instantiated only in main()?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!