java - Can't access functions in another class -


****edit** saying call

functiontesttest.numbercheck(usernumber); 

i have tried numerous times before posting on here didnt work.

people downvote question cant answer, great...

on project im working on couldn't call functions class. been trying fix day. decided throw a few lines of code & try call function class make sure didn't have unnoticed syntax error in main project.

can see problem here?

returning error:

cannot find symbol symbol: class functiontesttest location: class functiontest 

...

public class functiontest{    public static void main(string[] args){              scanner input = new scanner(system.in);      int usernumber = 0;      system.out.println("please enter number between 1 - 10");     usernumber = input.nextint();     functiontesttest ft = new functiontesttest();     functiontesttest.numbercheck(usernumber);    } } 

and..

public class functiontesttest{    public static void main(string[] args){   }    public static void numbercheck(int num){     if (num == 1){         system.out.println("function works");     }   } } 

the error caused because using class package. in case have import first before using.

if using ide there should hotkey fixing problem.

also...

you don't need create object instance access static methods of class. use:

functiontesttest.numbercheck(usernumber); 

it not recommended, can call static method on object instance like:

new functiontesttest().numbercheck(usernumber); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -