Win a copy of Terraform in Action this week in the Cloud forum!

Mike Mitchel

Greenhorn
+ Follow
since Nov 19, 2012
Mike likes ...
Eclipse IDE Linux
UK
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Mitchel

Thank you for the comments. I hope I won't get ambiguous questions in the real exam.

Mention two benefits of using ArrayList over array in software development.

(Choose two options.)
Select one or more:
A. Reduces memory footprint
B. Implements the Collection API
C. Is multi.thread safe
D. Dynamically resizes based on the number of elements in the list




My answer was B & D . But the correct answer is A & D . I am aware that A is bit ambiguous here. I saw a post in coderanch about it.But my concern is not about A , It is about B. But how on earth is B wrong?

As per the javadoc



java.util
Class ArrayList<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess



Am I missing some thing here ?
Thanks Henry. Yo explained it clearly. I have one doubt . Does that mean that any label which is not a block level is just ceremonial ? Compiler won't throw any error on declaring them except at variable declarations. But the labels (even inside a loop) are only useful if they are at a block level. Is my understanding correct ?
This is from Enthuware OCAJP 7 Mock



I was expecting compilation error as I thought label "loop" might not be recognized at line 2 as it is outside the for loop . But answer is "No compilation error and line 3 will be executed." .

Now I have added lines a,b,c & added a label to 3 . commented out line 2 . commented b & c independently. Both time it is a compile error saying "undefined label".

What does this mean ? I understand how finally works . But I can't understand the rules concerning transfer of control to labeled statements.

What is the role of block statement here ? I can see that loop3 is not in scope( ? ) . that may explain the error. what about loop 2 ? I am confused. Can somebody please explain.
Thanks Roel . Thats great explanation. Thanks tsang as well.
This is from whizlabs OCAJP 7 Mock



I was expecting class cast exception at run time. As String "0067" can't be added to a List<Integers>. But I am wrong, This compiles and prints 0067. Can somebody kindly explain?
Below code (Snippet 1) fails to compile in JDK 7.0_7 compiler (Error: reference to go is ambiguous, both method go(int...) in A and method go(java.lang.Integer...) in A match)

Snippet 1


Meanwhile this code (Snippet 2) compiles fine with JDK 7.0_7 and displays " primitive" on running. But the code doesn't compile on my other compiler Eclipse Compiler 0.A48 ( Error: The method go(int[]) is ambiguous for the type A. )


Snippet 2


So "snippet 2" seems to be an old compiler bug fixed in Java 7. What about "Snippet 1" ? Is this an unfixed bug with Java 7 compiler ? On the other hand , Is this compiler error a correct behaviour ? Can somebody kindly explain from the JLS .
Thanks a lot Roel . That makes sense. Excellent explanation.
7 years ago
from whizlab ocajp 7 mock

Given:


Which is true?
Select one:
A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The owner variable breaks encapsulation & would eventually affect polymorphism.
D. The simId and talkTime variables break polymorphism.
E. The setSimInfo method breaks encapsulation. Incorrect

The answer is C

But I couldn't understand the statement

& would eventually affect polymorphism



Could somebody please explain how lack of encapsulation affects polymorphism ?
7 years ago
thanks everybody for helping. now I got it.

thanks CR for your example , which cleared up things .

Let me explain my understanding



This one will create a new Object Item1 & assigns it to reference variable item1 which will leave alone the original object.



This one will change member in object referenced by item12.


I was expecting both these scenarios to be similar. my bad. :-(
8 years ago
I was attempting to solve programming exercise 10.2 in Khalidh Mughal book. The exercise was about hashCode() & equals() methods & concept of immutability.

As per my understanding the class Pair is still mutable. I was expecting p1 as

p1 item1 new item2

But what I got was this one

p1 item1 item2

I was expecting that reference at (1) will be able to change the obj1 value in Pair.

Could somebody please explain?



8 years ago
Helo Gurus,

HeadFirst Java , chapter one , cross words question 15 (downwards )

Q. Shocking modifier

A. static


What is so shocking about the keyword static ? Is Kathy / Berts hinting on some weird behavior of static variables/methods ? What are these weird behaviors ?

Thanks in Advance,
Mike
9 years ago