aspose file tools*
The moose likes Beginning Java and the fly likes static reference var & singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static reference var & singleton" Watch "static reference var & singleton" New topic
Author

static reference var & singleton

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi all,

I have one doubt in static.

I know the instance variables are one per object.
And the Static Variables are one per class.

I have used like below:
int i = 10; //Instance variable
static int i = 10; // Static Variable.

I comw across like this:
static Dog d = new Dog();

Pls explain the above line and its importance. And also I come across this cdoings in Singleton class and whether inheritance is possible in the singleton class. Since we are marking construtor as private. pls explain that too
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
If possible provide me some sample codings!!

Thanks!!
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
I tried some codings. pls go thru it.



Correct me,if i am wrong: In the above pgm.



If possible like above what will be the result for:
static ex e3 = new ex();
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You're on the right track here. A third instance will get its own copy of a,b and share c again.

If your class will modify c you have a great reason to read up on threads and synchronize.


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: static reference var & singleton