开发者

Calling own created java functions without an object?

I have 2 classes one of them is classmain and another is myclass the one contains my own functions. I want to call these functions without creating an object of myclass. In C++ creating an *.cpp file and including it to main.cpp is enough to call them. I'm using eclipse with android plug-in.

Thank you for help I forget to say that If I have a function in myclass named Function1

public int开发者_运维技巧 function1(){return 1;}

I want to call in main something like this:

int i = this.function1();

Thank you for any advice!


Use static methods.


you have to set the functions to static, so you can call the functions in this way:

MyClass.exampleFunction();

the function in your MyClass class looks like:

public static void exampleFunction(){}


use static keyword for your methods/functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜