+ 1
In java Math class have all static methods, then how can I use it inside non static method?
I tried to create Math object but it say it's private!
15 Respostas
+ 2
you cant: call non static method from static method
you can: call static method from both static and non static method
+ 3
alvin ouma please create a new post for this.
It is no related to this question.
+ 1
Show your code!
+ 1
you can use them directly, static method doesnt need to be call inside static scope.
ex.
Math.ceil(var)
+ 1
yes, but its the other way around.
you're calling static from non-static.
0
Fernando Pozzetti
Brother this on...line no 12
https://code.sololearn.com/c6BxceJC3hYa/?ref=app
0
Taste Tasty Yes!!! but as I asked in question what if my method scope is not stactic the how can I use Math class methods?
0
just use it like in line 16
0
Taste Omg it works but how? please explain...I have read somewhere that you can't call any non-static function from static until it's object is created!?
0
Taste Bro please little bit explain na....đ
It was supposed to not work...but it worked....and if it worked then how it worked!?
0
Taste Oh that's how it work...thank you so much!!!!
0
Saidvalikhuja Baykhujaev Thank you dear but Taste cleared all my doubt :)
0
The static methods belongs to the class not to objects. You can call the static methods without create an instance of the class. For do this in your code type the className.staticMethod()
Example:
Math.ceil(var);
0
we got a case of downvoter here.
maybe "they" havent read the guidelines :)
https://www.sololearn.com/Content-Creation-Guidelines/
- 1
If you read carefully you will find your answer. https://www.sololearn.com/learn/Java/2219/