aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the real answer? 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 "what is the real answer?" Watch "what is the real answer?" New topic
Author

what is the real answer?

Sanket Modi
Ranch Hand

Joined: Mar 10, 2008
Posts: 30
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?


Thanks and regards,<br />SanKet Modi
Padmanabh Sahasrabudhe
Ranch Hand

Joined: Mar 04, 2008
Posts: 53
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

Joined: Mar 12, 2008
Posts: 16
I tried in jdk1.5 but again I got the compilation error as incomaptible types
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Neha Java",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Mar 10, 2008
Posts: 1773
    
    7

  • 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 ]

    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: what is the real answer?