Globlab static variale
Hi I have declare globla static variable of object type and i initialily asign it as static Object s=""
I assign this object an other in constructor of class
But the thing is that i call this variable to on other class with it class name but it return same empty string string value i dont know why
please if you have any suggestion for it
I think I have some misunderstanding of static variable
I am having trouble understanding what you are trying to do.Could you post code examples and where you are having problems?
A static variable is associated with the class, not with a specific instance of that class, which makes it accessible without creating or referencing an object of that class. You say that your constructor sets the value to something other than "", but until you actually call that constructor by using
new WhateverYourClassNameIs();
the code in the constructor never gets called. So if you just access the variable like this:
WhateverYourClassNameIs.s
it will still have the value that you gave it originally, which is "".
Thanks for Imediate repy
Here i my class wher i declare static variableJPanel p ,p1;
JInternalFrame internalFrame;
JavaFileView jfv; // A User Defined class for file choosing
static Object getfilename="C:\\Program Files\\Microsoft Visual Studio\\VB98\\BIBLIO.mdb";
public DataBase() {
super("Internal Frame Demo");
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception ex1) {
System.err.println("Unsupported LookAndFeel: " );
}
jfv=new JavaFileView();
test =new AccessJDBCTest();
getfilename=jfv.setFileChooser();
jfv.setFileChooser(); This fuction open JfileChooser when i select a file it returned to getfilname static vriable
Here is an other class where i am get the value of getfilename variable
conn = AccessJDBCUtil.getAccessDBConnection( DataBase.getfilename);I call this variable over here when i run my program file chooser appear i select a file click ok no selection file name appeare when i print this variable i always return value which i assighn it at declarration time i dont know
I call this fuction after file chooser but instead it retun same value which i assingn this varaible at declaration time please Help
I still don't understand what you're trying to do, and I find your code most horrible (at least the part of that unformatted gunk I can read).
http://forum.java.sun.com/help.jspa?sec=formatting
Also, try to write legible posts. Did you know that commas and periods are used to separate sentences or parts of sentences from each other?
I Thingk You feel difficulty to read my Question Becauase of english is second language of me not my mother toungue
I will Try my Best .
Let there are Threee classed A, B, C
Class A {
static Object getfilename=" D:\as\ali.mdb";
public A(){
super("title");
B s=new B();
getfilname=B.readfilname();
C c=new C();
c.gtFilename();
}
Class B{
public Object readfilname(){
Object s=" C:\mydocudument\Biblo.mdb";
return s}}
Class C{
public void getFiename( Object f)
{
f=A.getfilename;
System.out.println(f);
}}
This is Imagianary code I write my Classes Just work as define above
But the result always come "D:\as\ali.mdb" . This program alway print this sentence. I dont why Why i donot pring "C:\mydcument\Biblio.mdb"
please Help Thanks for Quick reply