hi what is meant by static methods and static variable
balakrishnan.kb
0
Newbie Poster
Recommended Answers
Jump to PostThese methods and variables don't need an instance of the object to be used:
If in an object: MyObject there is the static variable: VAR and the static method method1(), then instead of:MyObject my=new MyObject(); String s = my.VAR; my.method1();
you can also do this:
Jump to Post…public class TestClass { public static int count=0; /** Creates a new instance of TestClass */ public TestClass() { } public static void main(String [] args) { TestClass tc1=new TestClass(); tc1.count=5; TestClass tc2=new TestClass(); System.out.println(tc2.count); //will print 5 NOT 0 TestClass.count=10; System.out.println(tc1.count); //will print 10 } }
All 5 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
Alex Edwards
321
Posting Shark
jigish
0
Newbie Poster
balakrishnan.kb
0
Newbie Poster
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.