What would be the result of compiling and running the following program?.
class Main {/*from www .ja va2s .co m*/ static Main ref; String[] arguments; public static void main(String[] args) { ref = new Main(); ref.func(args); } public void func(String[] args) { ref.arguments = args; } }
Select the one correct answer.
main()
cannot have a call to the non-static method func()
.func()
cannot access the static variable ref.main()
cannot be passed to the non-static method func()
.(e)
An object reference is needed to access non-static members.
Static methods do not have the implicit object reference this, and must always supply an explicit object reference when referring to non-static members.
The static method main()
legally refers to the non-static method func()
, using the reference variable ref.
Static members are accessible both from static and non-static methods, using their simple names.
No NullPointerException is thrown, as ref refers to an instance of Main.