Let's say I have two classes, Class1, and Class2.....
Class2 creates and instance of Class1 and calls one of it's methods like this:

Class 2
{
  Class1 c1  =new Class1();
   c1.myMethod();
}

Now, that would work...But, could you have just the class variable instead of the class instance variable like this:

Class 2
{
  Class1.myMethod();
 }

Or would that not work...What I was thinking, was in order to do that, Class1 would have to be static..Right?

Recommended Answers

All 2 Replies

Unless myMethod() is static it can only be called on an instance of the class it is defined in.

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.