can anyone explain me this concept that "static members of a class can access only static variables?" any simple code as an example to show this?
gourav1
-12
Posting Whiz in Training
Recommended Answers
Jump to Postit takes you about ten seconds to write this yourself...
have you tried it yet?
Jump to Postthe answer would be ... it can't.
just you try and run this:public static void main(String args[]){ // call a non-static method from a static context // or at least try to. printSomething(); } // non-static method public void printSomething(){ System.out.println("see?"); }
what IS possible, is …
Jump to PostYes, if you have a "non-static" object ("instance") you can use that to call non-static methods. This is true whether it's all happening inside a static or non-static method.
All 9 Replies
stultuske
1,116
Posting Maven
Featured Poster
gourav1
-12
Posting Whiz in Training
gourav1
-12
Posting Whiz in Training
stultuske
1,116
Posting Maven
Featured Poster
gourav1
-12
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
gourav1
-12
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
gourav1
-12
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.