This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests and have Scott Selikoff and Jeanne Boyarsky on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

SCJP 5: Question on Generics

 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

/*

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 ]
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one more question:

 
Pradeep bhatt
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2 IS THE ANSWER.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the question here?
Everyone (almost) knows it won't compile.
You'd know that too if you tried.
Are you asking why?
 
Pradeep bhatt
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic