About Question enthuware.ocajp.i.v8.2.1249 :
Moderator: admin
-
- Posts: 7
- Joined: Wed Feb 04, 2015 1:06 pm
- Contact:
About Question enthuware.ocajp.i.v8.2.1249 :
I have a doubt about the fact that main method accepts only a String Array parameter.
It's what I always knew, but in Mala Gupta Java 7 Certification Guide it's written:
The method must accept a method argument of a String array or a variable
argument of type String.
and
It’s valid to define the method parameter passed to the main method as a variable
argument (varargs) of type String:
public static void main(String... args)
so, is it totally wrong???
thanks
It's what I always knew, but in Mala Gupta Java 7 Certification Guide it's written:
The method must accept a method argument of a String array or a variable
argument of type String.
and
It’s valid to define the method parameter passed to the main method as a variable
argument (varargs) of type String:
public static void main(String... args)
so, is it totally wrong???
thanks
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
String[] and String... are same.
When you use String... the compiler allows you to pass any number of String arguments to that method but internally,
compiler converts String... to String[]. It also wraps the arguments into a String[] and invokes the String[] method. The JVM has no idea about String... It sees only String[].
The explanation has now been enhanced to include this point.
When you use String... the compiler allows you to pass any number of String arguments to that method but internally,
compiler converts String... to String[]. It also wraps the arguments into a String[] and invokes the String[] method. The JVM has no idea about String... It sees only String[].
The explanation has now been enhanced to include this point.
-
- Posts: 7
- Joined: Wed Feb 04, 2015 1:06 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
I didn't know that the compiler should convert String... to String[].
thank you for the explanation!
thank you for the explanation!
-
- Posts: 2
- Joined: Wed Oct 14, 2015 7:36 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
Just a little note about explanation of this question.
It is stated: "...Therefore, an exception will be thrown at runtime saying no main(String[] ) method found."
I find this somewhat misleading because "exception" can be understood here as java Exception. The problem is that actually Error (java.lang.NoSuchMethodError) will be thrown which does not extend Exception class. It extends java.lang.Throwable.
I got confused (for split second ofc
) reading this so... I just say.
It is stated: "...Therefore, an exception will be thrown at runtime saying no main(String[] ) method found."
I find this somewhat misleading because "exception" can be understood here as java Exception. The problem is that actually Error (java.lang.NoSuchMethodError) will be thrown which does not extend Exception class. It extends java.lang.Throwable.
I got confused (for split second ofc

-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
It is a common practice to call all sorts of Throwables as "exceptions" (with a small e). It does not imply the Exception class.
You will see the same practice followed in the real exam as well. Now that you have already encountered it, you will not get confused in the real exam
HTH,
Paul.
You will see the same practice followed in the real exam as well. Now that you have already encountered it, you will not get confused in the real exam

HTH,
Paul.
-
- Posts: 11
- Joined: Wed Jun 26, 2019 12:43 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
Just purchase the license and make BASIC test .
The strange issue that on question with enthuware.ocajp.i.v8,2,1249 I was redirected here (but ok not the issue) ...
The issue is definition:
- public static void main(String args) (?) where is vararg(...) here ????
The strange issue that on question with enthuware.ocajp.i.v8,2,1249 I was redirected here (but ok not the issue) ...
The issue is definition:
- public static void main(String args) (?) where is vararg(...) here ????
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1249 :
There is no ... in the code given in the problem statement. That is why the correct answer is "None of these".
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Who is online
Users browsing this forum: Google [Bot] and 10 guests