aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes object array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "object array?" Watch "object array?" New topic
Author

object array?

Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

I found this code on certPal
I wanted to know how come the compiler compiles the code fine even if we are missing the array brackets for the object ?


SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
Hi.

We didn't miss anything here.
When we initialize array of object (or primitives) thy are initialized with theirs default value.

Hope that this was helpful


SCJP 1.6 in progress ....
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

no no
I wanted to say
here
we are defining 2D array that means there should be [][] isn't it but in the declaration there is only [] so why doesn't it give compiler error?
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello,

Please Prasad, use meaningful subject lines. Please check MeaningfulSubjectLine

It is because it is an Object and anything is an Object in java. Be it two dimensional or one dimensional,
it doesn't matter. It can be assigned to Object. If you amend your code to something like this


It will give you a compile time error.

Hope this helps,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 308

Adding to that an Array is an object in Java.
So String[] is an Object.
String[][] is an Object[]

hope this is clear!


SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Rajeev Rnair wrote:Adding to that an Array is an object in Java.
So String[] is an Object.
String[][] is an Object[]

hope this is clear!


Pretty meaningful pointers Rajeev.

Best Regards,
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 308

Thank you Prithvi

forgot to add; String[][] is an Object too .
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
You are welcome CowBoy
When is your exam?

Best Wishes,
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

thanks prithvi and rajeev
got it now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: object array?