• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

can i call a consturctor from a static method?  RSS feed

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the format for calling a constructor ?
can i call a constructor from a non-static method ?
can i call a constructor from a static method or block?
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of those questions that can be answered by testing it yourself.
If I answer the first question for you:

you should be able to discover the answers to the other two questions yourself.
 
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Along with those,

try,

1) Static block
2) Object block ( which will be executed before constructor)

They will give good insight into object state loading.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Srinivas Kalvala:
Hello,

Along with those,

try,

1) Static block
2) Object block ( which will be executed before constructor)

They will give good insight into object state loading.



I don't see how. By "object block" are you referring to an instance initializer?
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the beginners forum...
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by saikrishna cinux:
what is the format for calling a constructor ?



You've entered more than 400 posts and you haven't created an object yet? Just what have you been doing?
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ken Blair:

I don't see how. By "object block" are you referring to an instance initializer?




Yes Ken, you are Right.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!