About Question enthuware.ocajp.i.v8.2.1249 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
giorgiadiro
Posts: 7
Joined: Wed Feb 04, 2015 1:06 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1249 :

Post by giorgiadiro »

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

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by admin »

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.

giorgiadiro
Posts: 7
Joined: Wed Feb 04, 2015 1:06 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by giorgiadiro »

I didn't know that the compiler should convert String... to String[].

thank you for the explanation!

andrix
Posts: 2
Joined: Wed Oct 14, 2015 7:36 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by andrix »

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.

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by admin »

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.

BaxLi007
Posts: 11
Joined: Wed Jun 26, 2019 12:43 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by BaxLi007 »

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 ????

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by admin »

There is no ... in the code given in the problem statement. That is why the correct answer is "None of these".

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1249 :

Post by admin »

BaxLi007 wrote:
Wed Jun 26, 2019 12:47 pm
The strange issue that on question with enthuware.ocajp.i.v8,2,1249 I was redirected here (but ok not the issue) ...
It is by design. The same question appears in v7 as well as in v8. That is why it is redirecting to the same thread.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests