954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

accessibility

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?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Thank you!

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You