• Post Reply Bookmark Topic Watch Topic
  • New Topic

Math f = null; and it works?  RSS feed

 
Alex Grig
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends.
Please explain why it works:

So if we can't instantiate Math, so it must be null?

------------------
Alex J.Grig
 
leena rane
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,
1.You are not instantiating the class since you are not using new.
2.yes f has null
3.sin(x) is a static method so it can be called even if f has null.
So no NullPointerException
4.if you try this with some other abstract class which you create and call a non-static method ,it will not be valid
HIH
 
Alex Grig
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks rane,
I get it for the code above.
Please clear up the following words
"It is ok to pass null as an argument to a method, as long as the method is expecting it. Some methods do; some do not. So, for example, System.out.println(null) is ok, but string.compareTo(null) is not."
What does it mean "as long as the method is expecting it."?
------------------
Alex J.Grig
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that the programmer has foreseen the value of the parameter, and the implementation of the method is prepared to deal with a null. ;-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!