Mike Okri

Ranch Hand
+ Follow
since Jun 22, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
9
Received in last 30 days
0
Total given
8
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Okri

Joanne Neal wrote:

Mike Okri wrote:If a nested Subclass extends a Superclass with a private constructor, Subclass cannot be instantiated outside Superclass.


It might be possible with reflection and the setAccessible method.



Oh yes. That's right.
7 years ago

James Boswell wrote:Mike

In the example you have given, how would you create an instance of Subclass outside of Superclass? You would need an instance of Superclass first which you cannot achieve (as it has no public constructor).



I'm saying that technically, it's not impossible to extend a class that has a private constructor. If a nested Subclass extends a Superclass with a private constructor, Subclass cannot be instantiated outside Superclass.
7 years ago

I Wayan Saryada wrote:The answer is you can't extend the Parent class if it has a private default constructor.


Technically, you can extend a class that has a private constructor if the subclass is a nested class.

7 years ago

sharma ishu wrote:Why is s not null as no argument has been passed to it.


The JVM initializes s to a zero length array (not null) if there are no command line arguments.

sharma ishu wrote:
This is my question. If static methods can't be inherited, then why is this illegal?


An inherited static method can be hidden by a static method (not an instance method). An instance method cannot override a static method.

sharma ishu wrote:
But since static methods are not overridden so this is just a redefinition in another class. Isn't it?


Static methods cannot be overridden but they can be inherited.

Tim Holloway wrote:I don't know how much "out of the box" this is.


I'm pretty sure that a puzzle like this is not designed for people of your calibre. I'm sure that a puzzle like this is designed to test whether a young programmer has the potential to blossom into a senior programmer with strong analytical skills. This puzzle will test whether he is clever enough to realize that lack of information is information. Not many young programmers are able to do this.
7 years ago

Tim Holloway wrote:As a measure of programming aptitude it fails, because one of the first things you want to do when solving a problem is to obtain as much data as possible. But this puzzle is predicated on the absence of something, not its presence.

To reference Sherlock Holmes: The dog didn't bark.


The puzzle tests "thinking out-of-the-box" intelligence and I don't blame companies for looking for people who possess this type of intelligence because they tend to be very good at analyzing complex real-world problems. Some programmers spend a lot of their time analyzing and looking for solutions to complex real-world problems. The puzzle gives you sufficient information and it's up to you what you do with that information:
  • the men cannot talk to each other
  • D can see C and B
  • C can see B
  • A & B can only see their respective sides of the wall
  • one man must call out the color of his hat


  • The only problem I have with the puzzle is that C cannot be 100% certain of the color of his hat. He can only be reasonably certain.
    7 years ago
    Life is really not a big deal. It’s a big deal to us (humans) because it applies directly to us and we are intrigued by it, but in the context of the universe as a whole, it’s not that big a deal. It’s just one of the random “things” that exists in the universe. Other random things that exist in the universe include planets, stars, black holes, dark matter, dark energy and many more that we have not discovered yet. When you die you simply transform from one thing to another thing. Today, you’re part of the human race, tomorrow you could be part of a planet or star. All things in the universe (including consciousness) are composed of or result from matter and/or energy and evolve over time.
    8 years ago

    vipul bondugula wrote:There is no need to synchronize removeFirst(). As the list itself is synchronized..


    The LinkedList is thread-safe but the removeFirst() method is not thread-safe. If you run the code multiple times, you'll find that it will periodically throw IndexOutOfBoundsException, hence the need to synchronize the removeFirst() method.

    Because the removeFirst() method is not thread-safe, the following sequence is possible:
  • thread t1 executes line 2
  • thread t2 executes line 2
  • thread t2 executes line 3
  • thread t1 executes line 3 -> IndexOutOfBoundsException

  • Don't Know What To Tell Ya by the beautiful Aaliyah
    8 years ago
    The code will periodically throw IndexOutOfBoundsException. One way to avoid this is to synchronize the removeFirst() method.

    Jeff Verdegan wrote:Were they introduced in some other corner of the Java universe prior to that?


    Where did you get the idea that they might have been introduced in some other corner of the Java universe prior to that?
    8 years ago
    Yes. Annotations are part of Java SE.
    8 years ago