wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classes" Watch "classes" New topic
Author

classes

vijay kaushik
Greenhorn

Joined: Jul 11, 2005
Posts: 3
can we intialise variables in a class without a constructor if so how ?
plz give desired examples.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This is unrelated to Threads, so I'm moving it to Java in General(Beginner).


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classes
 
Similar Threads
Doubt about diagram class (realization)
WA #1.....word association
Math class immutable
can non-static inner class access any member
andrew has wii