• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object array?

 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Dejan Miler
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to that an Array is an object in Java.
So String[] is an Object.
String[][] is an Object[]

hope this is clear!
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Prithvi

forgot to add; String[][] is an Object too .
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome CowBoy
When is your exam?

Best Wishes,
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks prithvi and rajeev
got it now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic