• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Objects and casting

 
Ranch Hand
Posts: 234
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I have absolutely no idea what goes on in this code: Glenn, Mitchell. OCAJP Oracle Certified Associate Java SE 8 Programmer Practice Exams (Kindle Locations 11714-11716). Enthuware. Kindle Edition.

Consider the following classes :

Identify options that will compile and run without error. Select 1 option
A. a = (B)( I) b;
B. b = (B)( I) a;
C. a = (I) b;
D. I i = (C) a;



I just have no idea what I've read here. Is there any sort of easy way to get my head around this mess of double casting objects to other references etc? Generally speaking I've noticed that I have quite a few problems with these kind of questions, and I'm not sure how to tackle them really, I usually draw the hierarchy on a piece of paper but still, it's questions like these that really confuse me. How do I know that one or the other compiles and run? Is ther some kind of general rule I can apply? he correct answer is A by the way
 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add to the above here is another example on the same note:

Which statements, when inserted in the code below, will cause an exception at run time?

Select 1 option
A.
B.
C.
D.
E.


I mean, is there a way to be sure which one will cause issues? Like, I know I can do A and B ( B needs an explicit cast, that's obvious) but C,D and E are not so obvious to me.
 
Enthuware Software Support
Posts: 4907
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This discussion should be helpful : http://enthuware.com/forum/viewtopic.php?f=2&t=1050

HTH,
Paul.

P.S. Not sure if you are aware of this but just in case - While going through a question on your kindle, you can click on the question id to view a discussion on that question. You may find the existing discussion helpful. If there is no existing discussion on a particular question, you can post your query.
 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK thanks, I have bought the book from amazon but I don't have a kindle so I'm browsing it on my laptop.
 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as a side note, I compiled and run the first example, and it seems that both A and B compile and run with no problem, here is the code:
 
author & internet detective
Posts: 42135
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Attin wrote:OK thanks, I have bought the book from amazon but I don't have a kindle so I'm browsing it on my laptop.


That book is a book of only practice exams. I think Paul is suggesting you buy an actual study guide. Practice questions are intended to supplement a study guide, not replace it. A study guide explains the things you are asking about. For example, Mala Gupta and I are authors of too different study guides for this exam.
 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got your book Jeanne :-)
 
Paul Anilprem
Enthuware Software Support
Posts: 4907
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Attin wrote:OK thanks, I have bought the book from amazon but I don't have a kindle so I'm browsing it on my laptop.


The link to forum feature works on browser as well. Just click on the question id to view the appropriate discussion thread for that question.

HTH,
Paul.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic