Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

classes  RSS feed

 
vijay kaushik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we intialise variables in a class without a constructor if so how ?
plz give desired examples.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is unrelated to Threads, so I'm moving it to Java in General(Beginner).
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try some of these ...

A static block can initialize static variables.

The variable declaration can include initial values.

The variable declaration can call a method. I just tried this for the first time.

String var = getVar();

A method like getVar must be very careful not to assume the object instance is fully initialized, eg passing a reference to "this" to some other object might get you in trouble.
[ July 11, 2005: Message edited by: Stan James ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!