Steven Wijn

+ Follow
since May 11, 2020
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steven Wijn

Kawe Ramon wrote:
Hello, did anyone who took this exam have to retest and get it for free? If so, what is the procedure?

Interested in this aswell
Thanks for your report and a big congrats!!

I'll be taking the exam also this week, having achieved the OCA 8 exam in the past (thanks to Enthuware also).
What would you say is the distribution of OCA/OCP topics in the exam?

I'm also preparing with the Enthuware exam (819 version) and I notice a lot of questions in those are about OCP related material. Is this also what I can expect in the real exam? I hope so, because I've been studying hard on that fulltime for two months now and I got it better in memory.

Junilu Lacar wrote:

Steven Wijn wrote:Without having tried compiling the code:I would guess it is valid and casting is redundant. b refers to a SoccerBall object and SoccerBall is-A Equipment, so using Equipment as a reference variable type is legit. From the responses above I gather that the object doesn't change, so the casting of (Equipment) should also be redundant.

Now try compiling/running it. What happens when you try removing the cast? Why?

You raise good questions, it didn't compile.

Indeed in that case the casting is necessary, because b is of ref.variable type Ball which is not compatible with equipment. We know that the object is of type SoccerBall, but the compiler does not.

I will look at the other question tomorrow. Thanks
1 year ago

Junilu Lacar wrote:
Also, these kinds of formulations are contrived. The casts are really redundant and the effect is the same as if you had just written this in the first place:

I have read all of your replies, thanks for the thorough responses.

This is indeed what I asked

Junilu Lacar wrote:Here's a puzzle that I think is more relevant to your confusion.

Given the following:

Is line 5 legal and if so, is the cast necessary or redundant? Try answering before you try to compile/run this code.

Without having tried compiling the code:

1 year ago

Junilu Lacar wrote:Did you try actually running the code to see what happens?

Casting never changes the actual runtime type of an object so whatever type it was created as, that's what it will be. Casting simply allows you to "see" the object as the type that you've casted it to.

Thanks for both of the responses above.
I actually answered both questions correctly. But the explanation of the question did not really get into the casting part of the question.

The part that confuses me is that in the study material I have only encountered casting in regards to the type of reference variable, not in scenario's like these.

Junilu Lacar wrote:In the second example, casting is a red herring. Look at the declaration of the classes and interfaces carefully.

Thanks again. I answered the question correctly, I understand that a class can't extend an interface and likewise can't implement a(n) (abstract) class. That's why I left the code out and only supplied it in the form of an external URL, it wasn't important to my question.

Maybe this makes it more clear:
Please only focus on the casting part, i.e:

class SoccerBall extends Ball implements Equipment

Equipment variableName = (Equipment)(Ball)new SoccerBall() -----> What type of object is created here?? is it still a SoccerBall object even though there are two casts before it?
1 year ago

I've been preparing for the OCA 8 exam and it's going pretty well. Using a few different resources; I began with the book of Mala Gupta, then read the book by Hanumant Deshmukh (really good), and currently preparing with Enthuware and Java 8 programmer practise tests.

I understand the use of and need of the casting of variables, but I have not seen a few cases that I met in chapter 7 of programmer practise tests by Jeanne Boyarsky and Scott Selikoff.

A simple but good example: (Chapter 7 Q32):
Full code uploaded here:

Helicopter h = (Helicopter)new Rotorcraft();

Question: What is happening here. I assume that the created object simply is of type Rotorcraft?

More complicated question (Chapter 7 Q24)
Full code uploaded here:

System.out.print(((Planet)new Mars()).methodname()));

Question: I know that when you create a new object without assigning it to a variable, it is assigned to an automatically created temporary variable (which after this line of code, the scope of it ends). With the casting of Planet before new Mars, does it create a temporary reference variable of type Planet or is the actual object casted to type Planet?

I hope this post makes sense, the question clear and I can get a good response.
Thank you in advance!
1 year ago