Sushant Kaushik

Greenhorn
+ Follow
since Dec 12, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sushant Kaushik

Hello Ranchers,

Today I gave my SCJP 5 and cleared it with 97% marks.
Thanks to all of you for being such a great help and last but not the least many thanks to K & B for such a wonderful book.

Cheers,
Sushant
15 years ago
Thanks Ruben, Its clear now
This code is from ExamLab-



Line1 is giving compilation error.

When I am removing final keyword from class C then there is no compilation error. How final keyword is affecting Line1.

Thanks,
Sushant
Thanks Henry for the explanation. This makes sense.
Thanks Sunil for the prompt response.

But List<Integer> can be assigned to both List<? super Integer> & List<? extends Integer>. Is it because that List<Number> can't hold reference of List<Integer> and that is the reason its complaining?

Hello Rancher,

This is a test program.

Why the below line of code doesn't compiles?



Thanks,
Sushant

Punit Singh wrote:

This is confusing. As far as i know Protected means Available to subclasses even outside Package. If outside pacakage then we can access the protected members via inheritance. Thats what i am doing. Isn't it? Then why compiler error?



This means you can use protected member using instance of subclass only, not the instance of superclass.
As protected member is inheritable, you can use thinking it as a member of subclass, but not a member of superclass if there is a package difference.

subclassinstance.protectedmember;//ok as subclass has this member via inheritence.
superclassinstance.protectedmember;//compiler error as accessing super class protected member outside the package.



@Punit, in the given program above, pack is an instance of SuperClass, then how compiler is not complaining when we are trying to access x2 from subclass using reference of SuperClass?


Thanks all. My doubt got clarified
This is test Program -


Output is - false

If I comment Line 1 then output is - true.

Can someone please explain why output is false when Line1 is not commented :roll:
What is the type of j after Line 1? is it still Integer or int? If its Integer then I can understand that output will be false. If its int then Output should be true. correct??
Got it...Thanks Henry & Alex..
Oops...I missed that...but still in Class B we can assume that runNow() method is overrideen even though its private in class A, isn't it??
This is from Diagnostic Test from Exam Lab -



Output is - High,High

I though the output will be Low,Out as run time Polymorphism will come into picture and runNow method in B & C would have been called respectively.

Thanks in advance.
Thanks Arie..now it got clarified
Source - K &B chapter 6, Page 455



The Output is -
before: Fido 35
after: Fido 42

This is fine as Animal class didn't implement Serializable interface so weight got its intialized value of 42.
My question is if I modify Animal class as -

The output is
before: Fido 35
after: Fido 0

Can somebody please explain why in this case I am getting 0 for weight instead of 42?

Thanks,
Sushant