Link to home
Start Free TrialLog in
Avatar of zizi21
zizi21

asked on

TestCAccount.java:13: non-static method print(CAccount) cannot be referenced from a static context

Hi,

I get the error below:

TestCAccount.java:13: non-static method print(CAccount) cannot be referenced from a static context
print(cDad);
^
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zizi21
zizi21

ASKER

Just wondering, if the main is static : public void static main(String [] args), i thought it is okay to make the print method static as well , but that did not work . If I do the instance of the class that would work. but in my lecture notes, there was no instance... we were learning on overriding and overloading...
well you could make the print method static, then you wouldn't get that error, but then if the print method itself makes references to non-static methods you'll get the same error in the print method and have to create an instance there...
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zizi21

ASKER

let me try it..i am a bit confused here..here..thanks
Avatar of zizi21

ASKER

sorry..just finished two other exams..going back to java..forgive me for the late reply...
You should typically be avoiding making things static.
You main should be creating an instance of a class (or classes) and calling (non-static) methods on those instances.
Avatar of zizi21

ASKER

thanks!