Recaip Sanli wrote:This surprisingly does the job, I still do not understand how though..
Circle c = new Circle();
c.findArea(4.5);
And Fred Kleinschmidt will explain why you can get that code to compile and why it is bad code. Maybe I'll explain it too, but going at it the other way round from Dave Tolls.
The findArea method, as FS told you yesterday, does not take any information from the object and does not send any information to the object. What it does is take information from the outside world (
via its parameters) and send it back to the outside world(
via its returned value). If you find the
most dubious classification of methods ever, you find that is a 1368; that method counts mathematically as a function. In that case, as FS says, you should consider making the method static, and static methods should be called on the name of the class, not the name of the reference to an object. The reason for using the class name is that static method are not ploymorphic and you can get dangerous confusion if you use the name of an object reference to call a static method on.
I have had to shorten the big numbers in your original post because
otherwise the post was too difficult to read. If you want a BigDecimal you can do this sort of thing:-
The compiler will catenate those Strings for you. Don't create a BigDecimal from a
double because you will get problems about precision. Remember those
double literals of yours can only be read in part; the
double datatype runs out of precision after the first 16 digits. Also, if you have more than about 155 digits before the decimal point in your number, squaring it might produce infinity as a result because you overflow the range of the datatype. The square root of the largest
double value is about 1.34078079299425963249e154.