• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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);
^
0
zizi21
Asked:
zizi21
2 Solutions
 
basicinstinctCommented:
You need to create an instance of the class before you can access its non-static methods, for example:

TestCAccount myclass = new TestCAccount();
myclass.print(cDad);
0
 
zizi21Author Commented:
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...
0
 
basicinstinctCommented:
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...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
>>there was no instance... we were learning on overriding and overloading...

Just to make it clear - static methods can be overloaded but not overridden
0
 
zizi21Author Commented:
let me try it..i am a bit confused here..here..thanks
0
 
zizi21Author Commented:
sorry..just finished two other exams..going back to java..forgive me for the late reply...
0
 
objectsCommented:
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.
0
 
zizi21Author Commented:
thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now