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);
^
zizi21Asked:
Who is Participating?
 
basicinstinctConnect With a Mentor Commented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
CEHJConnect With a Mentor Commented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.