This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the real answer? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 50
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: 1409

  • 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: what is the real answer?
     
    Similar Threads
    javax.crypto.BadPaddingException for AES when encrypting and decrypting multiple times
    Missing Return Statement
    how to cast array of bytes into array of int
    Variable initial values
    Arrays.fill( ) - java 2