I have this question on a homework assignment:
The method
foo()defined in the classQuizhas the following signature:public static double foo(double f). What can you say aboutfoo()?
It is a class method
It is an instance variable
It is an instance method
It is a class attribute
I am thinking it is a class method because foo() is declared in a class. Is the answer as straight-forward as I think?
The answer is that its a
class methoda field or a method declared with
staticis always an attribute or behavior of the class respectively.Non-staticvariables are one per object, where asstatic variablesare one perclass.
staticmethod do NOT have access to theNon-staticvariables or methods.staticmethods and variables can be called using theClass_Namewith"."(dot) operator.Though if the
classdo NOT haveprivate constructor(Math class has private constructor), then you can also create an instance to class to call the static methods or variables, but thats not the legal way to do it.You should also remember that, you can call
static methods or variablesusing a null Reference of theclassin which they reside…. Yes and it works….