Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple java inheritance question

Is it possible to extend the Math class and still use the Math class to call the extended method?

For example, I have a method public static double mean (LinkedList<? extends Number) I would like to call like this Math.mean(list). Is this doable? How?

Thanks.

like image 984
nunos Avatar asked Dec 31 '25 09:12

nunos


2 Answers

Doc Java.lang.Math is Final class, can't be extended
Update: Static Method can't be inherited & final class can't be extended.

like image 63
jmj Avatar answered Jan 01 '26 21:01

jmj


Even if Math wasn't final, you couldn't do this. You can't use a superclass to call a function defined in a subclass. By definition, a subclass has access to all non-private methods defined in the superclass, but a superclass does not have access to functions in a subclass.

like image 43
Jay Avatar answered Jan 01 '26 22:01

Jay