Jump to content
Larry Ullman's Book Forums

Why Can I Accesses Non Static Methods Via Static Context?


Recommended Posts

i am quite confuse about  accesses non static methods via static context. for example:

 

class Test{

function Test(){

}

 

}

 

you can accesses this method without creating object, how is it possible? 

 

Test::Test();

 

then why we need to write static ahead that method? what the difference between  static function Test() and function Test()? 

Link to comment
Share on other sites

A non-static method can be accessed without instantiation (creating an object) or with instantiation. The static keyword is not really a restriction, it's a way to make a class or function be globally shared and accessible.

Link to comment
Share on other sites

 Share

×
×
  • Create New...