Mukta Pradhan

+ Follow
since Jan 17, 2018
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 Mukta Pradhan

thank you for the explanation.

I do not have doubt about whether the members of an interface can be static.
What I meant was the member class inn the interface is static by default.

I wrote a sample code

So the inner classes declared inside an an interface are by default  static.

Also, enum declarations are not allowed inside static methods or static blocks as well.
It gives compilation error- enum types must not be local.
Is itt similar to how static fields cannot be declared inside a method?
Also one more question is why enums are not allowed in member inner classes and only in static inner classes?
Are member inner classes defined in an interface are actually static?

Because when i try to define an enum in a member inner class in a concrete class, it gives me compilation error - enum declarations only allowed in static contexts. Also it can contain static methods.

Whereas when i try to define an enum inside a inner class in an interface, there is no compilation error.

If a question is given in an OCP where some imports are mentioned but not all required imports.
Then what should assume that the import is missing right if it is without line numbers?

There is one question in OCP Practice set Chapter 16 qn 24

I answered this as Code will not compile. But that was not the expected answer.

If imports are not at all given, then yes we assume the imports are given.

Also is some of the questions the code starts with package name.
In that case as well we have to assume the imports.

I am very much confused about this
There is a stmt
Runnable r1 = () -> Stream.of(1,2,3).parallel();

Acoording to the answer this line of code will compile.
But this lambda returns a Stream, then how can it be assinged to Runnable?
The SuperClass does not meet the properties of preventing methods from being overridden.
But, this class is currently immutable as we wont able to change its field s.

Question is which statement about above class is correct.

And the answer given in the book is:
The method compiles and returns a Path value that is always equivalent to Path object.

But, in case the Path is a relative path, then it will enter the if and will return the absolute path, so it will not be same.
I think, the answer should be:
The method compiles and returns a Path value that may not be equivalent to input argument.
Or am I missing something here?
The Immutable reference to a mutable subclass will not have access to the fields of mutable class in above example 'i'
Only after casting it to the mutable subclass it will have access to fields and methods and can change it.
The subclass can be mutable but the parent class will be immutable. I think...
If methods are final and class is not final then the class that inherits this cannot override the methods, and it will not have access to the private fields of parent class.
So, that should be okay.
Thank you!

What if methods are final but class is not final, is it a proper implementation of Immutable class?
Chapter 11 Java Class Design Review Questions question 14
Answer in book is option B Plant.
But Plant getter methods are not final, so it is not immutable class.

Question 32 is also similar where answer is A -Flower and not Plant because it does not have final getter methods.

So, answer to the 14 th question should be option D - none