JavaChallenge46

Govinda Raj
wolfie/JavaChallenge
Aug 8, 2022

--

#AccessModifiers #threads #randomClass

Will the above code snippet compile or not?

Try to solve the challenge by yourself.

Let's understand the concept first —

There is a final class which means it can not be inherited. There is a thread also which consumes a Runnable having a run() method and it uses the constant from the Constants class, so now questions are —

  1. Can we use a constant from the final class in another class?
  2. Can Anonymous implementation of Runnable use the constant from another constant class?

Of course, a constant can be accessed from another class but the problem here is that you can only use static variables in static or top-level classes, and we’ve got a static variable in a class that isn’t top-level.

I hope you liked the challenge, if you do please subscribe to the publication for more such challenges.

Thanks.

--

--

Govinda Raj
wolfie/JavaChallenge

Senior Software Developer. Tech Enthusiast and love coding. My portfolio: https://govinda-raj.github.io/