0

I cant understand thr error is coming of non-static method power(int,int) cannot be referenced from a static context....!

function main()to pass the value of m and n and display the calculated result

5th Jul 2017, 5:25 PM
denise lartius
denise lartius - avatar
3 Antworten
+ 2
On Line 54 there is a typo... ... ... ... ...
5th Jul 2017, 5:46 PM
AgentSmith
+ 2
So the static member cannot be dereference is an error that occurs when you call a non-static member from a static member. As the other answers showed, no code, no answers. So if you don't show the code idk how to fix your problem. But this is why that causes an error, so you can fix your own problem: Think of what static means. The member is bound to the class. If I don't have static the member is bound to an INSTANCE of the class. So, if I'm in a static member I can't access something that's part of an object instance without actually having that instance. Example: int nonStatic; static void example(){ nonStatic = 5; // error } Which instance of the class am I changing the non static variable in? Idk because the static method isn't in any instance. I suggest getting further into OOP if this is confusing. To further explain what I mean, here's an example that won't cause an error. class Program{ static Program instance = new Program(); int nonStatic; static void example(){ instance.nonStatic = 15; // NO error System.out.println(instance.nonStatic); // Output: 15 } }
5th Jul 2017, 8:37 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Do you perhaps have a code to show that contains your errors?
5th Jul 2017, 5:27 PM
Ghauth Christians
Ghauth Christians - avatar