• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

array

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A{
String[] x;
int[] a[]={{1,2},{1}};
Object c =new long[4];
Object[] d =x;
}
will this compile?
can anyone explain this program to me
 
Ranch Hand
Posts: 57
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What problem you do have??
It will compile
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,what actually you are not able to get.I am trying to expalin the program.
In this program an array of string is declared,a two dimensional array having two rows of (1,2)and (1,0).An object of class Object referencing an array of long and and an array of object cross referencing object c.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Hasitha

will this compile?
can anyone explain this program to me


This program wont compile. add main method and check it. because array x is not initialized.
you can assign any object to 'Object' class and any array to a array of Objects. or even directly to Object. But the array dimension on left should be more.

so Object[] d = x; wont compile because x is just declared but dont have any data.
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


so Object[] d = x; wont compile because x is just declared but dont have any data.


It compiles.
'x' is null, hence valid value.
 
Kiran Tarte
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It compiles.
'x' is null, hence valid value.



I am saying it won't compile if you add it in main.


This compiles because all are instance variable.
but this rule doesn't applicable to local variable.
 
Not so fast naughty spawn! I want you to know about
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic