+ 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!

7th Mar 2020, 10:12 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
15 Respostas
+ 2
you cant: call non static method from static method you can: call static method from both static and non static method
7th Mar 2020, 12:20 PM
Taste
Taste - avatar
+ 3
alvin ouma please create a new post for this. It is no related to this question.
8th Mar 2020, 9:51 AM
Oma Falk
Oma Falk - avatar
+ 1
Show your code!
7th Mar 2020, 10:25 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
+ 1
you can use them directly, static method doesnt need to be call inside static scope. ex. Math.ceil(var)
7th Mar 2020, 10:31 AM
Taste
Taste - avatar
+ 1
yes, but its the other way around. you're calling static from non-static.
7th Mar 2020, 10:54 AM
Taste
Taste - avatar
7th Mar 2020, 10:36 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
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?
7th Mar 2020, 10:37 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
just use it like in line 16
7th Mar 2020, 10:46 AM
Taste
Taste - avatar
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!?
7th Mar 2020, 10:52 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
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!?
7th Mar 2020, 12:18 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
Taste Oh that's how it work...thank you so much!!!!
7th Mar 2020, 12:21 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
Saidvalikhuja Baykhujaev Thank you dear but Taste cleared all my doubt :)
8th Mar 2020, 4:37 PM
I Am a Baked Potato
I Am a Baked Potato - avatar
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);
9th Mar 2020, 4:12 AM
weaq321
weaq321 - avatar
0
we got a case of downvoter here. maybe "they" havent read the guidelines :) https://www.sololearn.com/Content-Creation-Guidelines/
9th Mar 2020, 6:08 AM
Taste
Taste - avatar
- 1
If you read carefully you will find your answer. https://www.sololearn.com/learn/Java/2219/
8th Mar 2020, 4:14 PM
Saidvalikhuja Baykhujaev
Saidvalikhuja Baykhujaev - avatar