Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object cannot refer to a primitive ?

 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In Q17 of the end of the book Mock Exam in the Gupta book the last option says that "a primitive variable can't refer to an object and vice versa". What about when a wrapper object refers to a literal value or a primitive variable? Please see my example code below.



Regards,

Ted
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends of course on the definition of an object.

If we think String then the statement is definitely true. int i = "abc"; and String s = 100; will not compile. But with wrapper classes it's a different story.

Is it possible that wrapper classes, autoboxing and unboxing are topics covered in the OCPJP7 (instead of the OCAJP7)? Based on the exam topics of both exams (OCAJP7 and OCPJP7) I would say they are.
 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,

That makes sense. I will just have to forget about wrapper classes for the OCAJ7 P1 exam.

Thank-you for the helpful reply Roel.

Regards,

Ted
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic