wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exam lab2(question 34) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exam lab2(question 34)" Watch "exam lab2(question 34)" New topic
Author

exam lab2(question 34)

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432


above code compiles fine.
line1 i think this is returning String [](String array),then how it can be assigned to Object type safe list?

SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
I am not sure but I guess it(string array) is considered as an Object(since arrays are Objects) and added to a list which accepts Object arrays.

Someone please correct me if I am wrong.


SCJP 1.6 96%
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

Neha Daga wrote:I am not sure but I guess it(string array) is considered as an Object(since arrays are Objects) and added to a list which accepts Object arrays.
hi neha thanks for reply
i think you are right if above line compiles fine.but how,it is voilating the rule of generics.
btw this is the actual question

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Arjun!

With arrays you can do an assignment such as the subtype array can be treated as the supertype array. In other words, following is correct:



as the array of Strings can be treated as array of Objects.
Moreover, when talking about generics, following is correct:



as you can add a subtype of an Object to the Object list.

When you combine the first feature with the second one into the following, the add operation is valid:


as the String[] is an array of subtypes of Object.

OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
well I guess any array can be assigned to an array of its superclass.For example if class B extends class A then,
A[] a = new b[5];
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
oh its already answered.
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

thanks pedro and neha,for your precious time.
your answers are worth while and understandable,i have made a note of it already
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

No problem mate!

Glad we could help :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exam lab2(question 34)