• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the real answer?

 
Sanket Modi
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had a question in one mock exam:

Is this legal?
long longArr[];
int intArr[] = { 7 ,8 , 9};
longArr = intArr;

the answer was:
You cannot assign a reference to an array of primitives
to another unless they contain the same primitive types.

but i think in java 5 (tiger) this rule is deprecated. am i right?
 
Padmanabh Sahasrabudhe
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this in jdk 1.6 > i got compile error

PrimArray.java:8: incompatible types
found : int[]
required: long[]
longArr = intArr;
^
1 error
 
Neha Agarwal
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried in jdk1.5 but again I got the compilation error as incomaptible types
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanket Modi,

When you post mock questions to the ranch, it is important that you quote the source of the the question.
Questions posted without a source are subject to being deleted.

-Ben
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • Any array reference may be assigned to a reference of type Object (class), Serializable (interface) or Cloneable (interface).
  • An object array reference may be assigned only to another object array reference if and only if the element type of the object array reference you are assigning has an IS-A relationship with the element type of the object array reference you are assigning it to.
  • A primitive array reference may only be assigned to an other primitive array reference if and only if both references are of the same type.


  • [ March 12, 2008: Message edited by: Jelle Klap ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic