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

TypeSafety

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, This is from Whizlabs..Code, question and my assumptions are given below. Please advice.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

How will this line compile? List is an interface, there is no new keyword and its missing brackets at the end.

For answer 1 and 2 I agree with you.
You can never instantiate a wildcard type, this is why this line doesn't compile.
The 2nd line doesn't compile as aa might not have been initialized. Otherwise it compiles fine which makes answer 3 correct...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi Ankit, assignment means, option2 at Line 42 is assigning at Line 26 "list" reference variable (or) reference variable "aa" at line 54 is assigning to bb (or) both ?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Technically when you pass some variables in a method call, its not assignment. But most of the rules that apply to assignment will apply to it. So in this case, rules of generics apply to both line 54 and 42...
 
wood burning stoves
 
subject: TypeSafety