File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP 5: Question on Generics 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 "SCJP 5: Question on Generics " Watch "SCJP 5: Question on Generics " New topic
Author

SCJP 5: Question on Generics

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844


/*

what will be the output?

1)SCJP SCWCD
2)no output.
3)It will not compile.

*/

( tags added, option numbering typo fixed)

[ January 11, 2005: Message edited by: Barry Gaunt ]

(Modified topic title to emphasize that it is for the new SCJP 5 beta exam)
[ January 12, 2005: Message edited by: Barry Gaunt ]

Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

3


Groovy
Pratap Rana
Greenhorn

Joined: Dec 15, 2004
Posts: 15
It will not compile.

For more explanation look at the Topic "2.8 Generics and Type Conversions" explained in the book "Java 1.5 Tiger: A Developer's Notebook"
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

one more question:

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

2 IS THE ANSWER.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
What is the question here?
Everyone (almost) knows it won't compile.
You'd know that too if you tried.
Are you asking why?


Tony Morris
Java Q&A (FAQ, Trivia)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Tony Morris:
What is the question here?
Everyone (almost) knows it won't compile.
You'd know that too if you tried.
Are you asking why?


Why dont you post some mock questions here for the beta exam?
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844


What is the question here?
Everyone (almost) knows it won't compile.
You'd know that too if you tried.
Are you asking why?


You can post some mock question and let others to post the answers.
As we know there is no mock exams for Java 1.5. This is the way to prepare for tiger exam.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Actually it prints:

[Java, Added]

which is interesting because it implies that it is first converted to an array and then java.util.Arrays.toString is used to print it.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844



Actually it prints:

[Java, Added]

which is interesting because it implies that it is first converted to an array and then java.util.Arrays.toString is used to print it.



Barry,
Can you explain it?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Barry Gaunt:
Actually it prints:

[Java, Added]

which is interesting because it implies that it is first converted to an array and then java.util.Arrays.toString is used to print it.


For %s

If the argument is null, then the result is "null". If the argument implements Formattable, then its formatTo method is invoked. Otherwise, the result is obtained by invoking the argument's toString() method.

So AbstracCollection's toString method is invoked.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Explaination. You are passing list and list1 both reference the same ArrayList, so you can add a String to list1, but you wouldn't be able to add a String to list. But since list is still pointing to the same ArrayList it will have the second added String in the ArrayList and print it.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

What is the question here?
Everyone (almost) knows it won't compile.
You'd know that too if you tried.
Are you asking why?


My bad - I was responding to the original post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP 5: Question on Generics