Jyoti Kaushal

Ranch Hand
+ Follow
since Jun 27, 2015
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jyoti Kaushal

Hi,

When I compare following :

String a = "Hello";
String b = "Hello";

a == b is true as it goes to StringPool

But if I do something like this:-



This doesn't comes out to be true. How is this manipulated by the JVM?

Thanks in advance.
Thanks a lot Sergej. Very well explained. Although it took little time for me to understand the things but finally I got the point.
Hi Ankit,

Correcting my words array contains 3 references so in my first line " Dozens [] da = new Dozens[3]; ", only one object is created. So, now things gets more complicated. How do we get 5 objects create din this? And same for GC, how to we get 2 objects ?
Sure
First question
1. Dozens [] da = new Dozens[3];
Here one array object is made i.e da. It contains 3 objects which are null(default vale for objects) currently as they have not been assigned any value.

2. da[0] = new Dozen();
Dozens d = new Dozens();
2 objects created here One assigned to d[0] and another one d.

So, I think 3 objects are created. But answer says 5 objects

Second question
d = null and d[1] = null. Both refer to same object so only 1 Object is eligible for GC but answer says 2 objects
I got where I was wrong. My Stupidity Was thinking System out is in if block.

Thanks:-)
I have the following code:-



Command given in command-line:-

java Hilltop eyra vafi draumur kara

I solved this question as follows:-

args array length is 4 and horses array length is 5.
First for loop will be executed 4 times (i < 5). Inside that we have if( i < args.length) , so this will work only till i = 3.

According to this output is :- EYRA VAFI DRAUMUR KARA.

Please correct me where I am wrong...
This is a question from Kathy and Bert book. I could not get the correct answer



It asks how many objects are created in main() and how many are elligible for GC when code reaches //do stuff.
Can someone please help me solve this??

Thanks in advance
Sergej,

The thing which I understood with your example is that issue is in the violation rule of overriding. But the issue basically is in the unhandled exception. Therefore, once I catch the exception using try catch the code works fine.
Thanks everyone for the replies. I understand the fact that if I catch the Exception then code works fine and prints Horse eats. The question which I am asking is that if I don't catch the Exception compiler error occurs :-


^

Trying to understand the exception, It looks like it didn't override the method and executed the superclass version. I expected error something like "Error in override or illegal override". I want to know how the compiler reacted in this case and gave such error? I am sorry if the question seems little weird .
Hi,

I thought polymorphic reference and overriding is clear to me but I got stuck when I found this. I understand the fact that always overridden method is executed in case of Polymorphic reference(Superclass reference and subclass instance). For example:-



Output will be:- Horse eats.

But when I add throws Exception with Animal eats method why does Animal eat() method is executed?


I think, that here it violates rules of overriding and hence no overriding happens here. Therefore, Superclass method is called. But I am not sure with this.

Thanks in advance
Hi Alex,

So does it mean that if an array is not initialized then it is a subtype of only Object class. Once initialized (Foo[0] or Foo[1] etc) then it is the subtype of that particular class too.
Thanks for the suggestion guys
Hi,

I have following code to check for instanceof



As per my understanding, this is an array of type Foo. So it should be instanceof Foo and also of Bar, Face because Foo extends Bar, Bar implements Face. Can someone please tell why I am wrong here?
Hi,

I am preparing for OCA from Kathy And Bert book and may be my question will sound little funny. Till now I have completed 3 chapters and 3 are left. While doing exercises, I could solve just 30-40%. Now I am confused that should I continue with the rest of the chapters and take some mock tests at the end or are there some chapter-wise practice questions which I could solve to get confident with each chapter as I complete it ??

Thanks in advance.
Hi Dev,

As per my experience, OCA/OCP certification will help you get deeper knowledge of core concepts. Of-course, you can learn frameworks at this stage but I would prefer you have a strong core java base before going further.

All the bst

Thanks,
Jyoti